Skip to content

Commit

Permalink
Add more log on verify segment and add a fix command
Browse files Browse the repository at this point in the history
Signed-off-by: xiaofanluan <[email protected]>
  • Loading branch information
xiaofan-luan committed Dec 1, 2023
1 parent 96058cb commit d1286bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 14 additions & 6 deletions states/kv/kv_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,33 @@ func (c *FileAuditKV) Save(ctx context.Context, key, value string) error {

func (c *FileAuditKV) Remove(ctx context.Context, key string) error {
fmt.Println("audit delete", key)
kv, err := c.cli.removeWithPrevKV(ctx, key)
val, err := c.cli.Load(ctx, key)
if err != nil {
return err
}

err = c.cli.Remove(ctx, key)
if err != nil {
return err
}
c.writeHeader(models.OpDel, 1)
c.writeLogKV(kv)
c.writeKeyValue(key, val)
return nil
}

func (c *FileAuditKV) RemoveWithPrefix(ctx context.Context, key string) error {
fmt.Println("audit delete with prefix", key)
kvs, err := c.cli.removeWithPrefixAndPrevKV(ctx, key)
val, err := c.cli.Load(ctx, key)
if err != nil {
return err
}
c.writeHeader(models.OpDel, int32(len(kvs)))
for _, kv := range kvs {
c.writeLogKV(kv)

err = c.cli.RemoveWithPrefix(ctx, key)
if err != nil {
return err
}
c.writeHeader(models.OpDel, 1)
c.writeKeyValue(key, val)
return nil
}

Expand Down
11 changes: 6 additions & 5 deletions states/verify_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func getVerifySegmentCmd(cli kv.MetaKV, basePath string) *cobra.Command {
for _, l := range statslog.Binlogs {
_, err := minioClient.StatObject(context.Background(), bucketName, l.LogPath, minio.StatObjectOptions{})
if err != nil {
fmt.Println("failed to check ", l.LogPath, err)
errResp := minio.ToErrorResponse(err)
if errResp.Code != "NoSuchKey" {
fmt.Println("failed to check ", l.LogPath, err, errResp.Code)
if errResp.Code == "NoSuchKey" {
if item.tag == "binlog" {
fmt.Println("path", l.LogPath, fix)
splits := strings.Split(l.LogPath, "/")
logID, err := strconv.ParseInt(splits[len(splits)-1], 10, 64)
if err != nil {
Expand All @@ -90,7 +91,7 @@ func getVerifySegmentCmd(cli kv.MetaKV, basePath string) *cobra.Command {
fmt.Println("failed to parse collectionID")
}

if fix && err != nil {
if fix && err == nil {
err := common.RemoveSegmentInsertLogPath(context.Background(), cli, basePath, collectionID, partitionID, segmentID, fieldID, logID)
if err != nil {
fmt.Println("failed to remove segment insert path")
Expand Down Expand Up @@ -123,7 +124,7 @@ func getVerifySegmentCmd(cli kv.MetaKV, basePath string) *cobra.Command {
fmt.Println("failed to parse col id")
}

if fix && err != nil {
if fix && err == nil {
err := common.RemoveSegmentStatLogPath(context.Background(), cli, basePath, collectionID, partitionID, segmentID, fieldID, logID)
if err != nil {
fmt.Println("failed to remove segment insert path")
Expand All @@ -150,7 +151,7 @@ func getVerifySegmentCmd(cli kv.MetaKV, basePath string) *cobra.Command {
fmt.Println("failed to parse col id")
}

if fix && err != nil {
if fix && err == nil {
err := common.RemoveSegmentDeltaLogPath(context.Background(), cli, basePath, collectionID, partitionID, segmentID, logID)
if err != nil {
fmt.Println("failed to remove segment insert path")
Expand Down

0 comments on commit d1286bc

Please sign in to comment.