-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: Sync v1.0.x pr to main branch (part4) (#357)
Related to #332 #334 #335 #336 #337 #338 #339 #340 #343 #344 #346 --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com> Signed-off-by: bigsheeper <yihao.dai@zilliz.com> Signed-off-by: Wei Liu <wei.liu@zilliz.com> Co-authored-by: yihao.dai <yihao.dai@zilliz.com> Co-authored-by: wei liu <wei.liu@zilliz.com>
- Loading branch information
1 parent
9f0d33c
commit f41743b
Showing
35 changed files
with
680 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ before: | |
builds: | ||
- env: | ||
- CGO_ENABLED=1 | ||
main: ./cmd/birdwatcher | ||
goos: | ||
# - linux | ||
#- windows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ before: | |
builds: | ||
- env: | ||
- CGO_ENABLED=1 | ||
main: ./cmd/birdwatcher | ||
goos: | ||
- linux | ||
#- windows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
_ "github.com/milvus-io/birdwatcher/asap" | ||
"github.com/milvus-io/birdwatcher/bapps" | ||
"github.com/milvus-io/birdwatcher/common" | ||
"github.com/milvus-io/birdwatcher/configs" | ||
"github.com/milvus-io/birdwatcher/states" | ||
) | ||
|
||
var ( | ||
oneLineCommand = flag.String("olc", "", "one line command execution mode") | ||
simple = flag.Bool("simple", false, "use simple ui without suggestion and history") | ||
restServer = flag.Bool("rest", false, "rest server address") | ||
webPort = flag.Int("port", 8002, "listening port for web server") | ||
printVersion = flag.Bool("version", false, "print version") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
var appFactory func(config *configs.Config) bapps.BApp | ||
|
||
switch { | ||
// Print current birdwatcher version | ||
case *printVersion: | ||
fmt.Println("Birdwatcher Version", common.Version) | ||
return | ||
case *simple: | ||
appFactory = func(*configs.Config) bapps.BApp { return bapps.NewSimpleApp() } | ||
case len(*oneLineCommand) > 0: | ||
appFactory = func(*configs.Config) bapps.BApp { return bapps.NewOlcApp(*oneLineCommand) } | ||
case *restServer: | ||
appFactory = func(config *configs.Config) bapps.BApp { return bapps.NewWebServerApp(*webPort, config) } | ||
default: | ||
defer handleExit() | ||
// open file and create if non-existent | ||
file, err := os.OpenFile("bw_debug.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer file.Close() | ||
|
||
logger := log.New(file, "Custom Log", log.LstdFlags) | ||
|
||
appFactory = func(config *configs.Config) bapps.BApp { | ||
return bapps.NewPromptApp(config, bapps.WithLogger(logger)) | ||
} | ||
} | ||
|
||
config, err := configs.NewConfig(".bw_config") | ||
if err != nil { | ||
// run by default, just printing warning. | ||
fmt.Println("[WARN] load config file failed, running in default setting", err.Error()) | ||
} | ||
|
||
start := states.Start(config) | ||
|
||
app := appFactory(config) | ||
app.Run(start) | ||
} | ||
|
||
// handleExit is the fix for go-prompt output hi-jack fix. | ||
func handleExit() { | ||
rawModeOff := exec.Command("/bin/stty", "-raw", "echo") | ||
rawModeOff.Stdin = os.Stdin | ||
_ = rawModeOff.Run() | ||
rawModeOff.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package remove | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/samber/lo" | ||
|
||
"github.com/milvus-io/birdwatcher/framework" | ||
"github.com/milvus-io/birdwatcher/models" | ||
"github.com/milvus-io/birdwatcher/states/etcd/common" | ||
etcdversion "github.com/milvus-io/birdwatcher/states/etcd/version" | ||
) | ||
|
||
type DirtyImportingSegment struct { | ||
framework.ParamBase `use:"remove dirty-importing-segment" desc:"remove dirty importing segments with 0 rows"` | ||
CollectionID int64 `name:"collection" default:"0" desc:"collection id to filter with"` | ||
Ts int64 `name:"ts" default:"0" desc:"only remove segments with ts less than this value"` | ||
Run bool `name:"run" default:"false" desc:"flag to control actually run or dry"` | ||
} | ||
|
||
// DirtyImportingSegmentCommand returns command to remove | ||
func (c *ComponentRemove) DirtyImportingSegmentCommand(ctx context.Context, p *DirtyImportingSegment) error { | ||
fmt.Println("start to remove dirty importing segment") | ||
segments, err := common.ListSegmentsVersion(ctx, c.client, c.basePath, etcdversion.GetVersion(), func(segment *models.Segment) bool { | ||
return (p.CollectionID == 0 || segment.CollectionID == p.CollectionID) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
groups := lo.GroupBy(segments, func(segment *models.Segment) int64 { | ||
return segment.CollectionID | ||
}) | ||
|
||
for collectionID, segments := range groups { | ||
for _, segment := range segments { | ||
if segment.State == models.SegmentStateImporting { | ||
segmentTs := segment.GetDmlPosition().GetTimestamp() | ||
if segmentTs == 0 { | ||
segmentTs = segment.GetStartPosition().GetTimestamp() | ||
} | ||
if segment.NumOfRows == 0 && segmentTs < uint64(p.Ts) { | ||
fmt.Printf("collection %d, segment %d is dirty importing with 0 rows, remove it\n", collectionID, segment.ID) | ||
if p.Run { | ||
err := common.RemoveSegmentByID(ctx, c.client, c.basePath, segment.CollectionID, segment.PartitionID, segment.ID) | ||
if err != nil { | ||
fmt.Printf("failed to remove segment %d, err: %s\n", segment.ID, err.Error()) | ||
} | ||
} | ||
} else { | ||
fmt.Printf("collection %d, segment %d is dirty importing with %d rows, ts=%d, skip it\n", collectionID, segment.ID, segment.NumOfRows, segmentTs) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fmt.Println("finish to remove dirty importing segment") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.