Skip to content

Commit

Permalink
cli: add dump-bin-put
Browse files Browse the repository at this point in the history
This command is used for keep container with blocks for
blockfetcher updated.

Close #3578

Signed-off-by: Ekaterina Pavlova <[email protected]>
README: add archival notice (#520)

People are likely to find this repo and we better have some directions for them.

Signed-off-by: Roman Khimov <[email protected]>
Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Sep 27, 2024
2 parents f20aa41 + 01a4878 commit 2938069
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions cli/server/dump_bin_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func downloadPut(ctx *cli.Context) error {
}
defer clientSDK.Close()

//sessionToken, err := createSessionToken(*acc, containerID)
//if err != nil {
// return fmt.Errorf("failed to create session token: %w", err)
//}
sessionToken, err := createSessionToken(*acc, containerID)
if err != nil {
return fmt.Errorf("failed to create session token: %w", err)
}

endpoint := ctx.String(options.RPCEndpointFlag)
rpcClient, err := rpcclient.New(ctx.Context, endpoint, rpcclient.Options{
Expand All @@ -82,35 +82,35 @@ func downloadPut(ctx *cli.Context) error {
return fmt.Errorf("failed to get current block height from RPC: %w", err)
}
log.Println("Current block height:", currentBlockHeight)
currentBlockHeight = 423894
//maxBlockIndex, err := fetchMaxBlockIndex(ctx.Context, clientSDK, containerID, acc.PrivateKey(), uint(currentBlockHeight), attribute)
//if err != nil {
// return fmt.Errorf("failed to fetch max block index from container: %w", err)
//}
//log.Println("Max block index in NeoFS:", maxBlockIndex)
//if maxBlockIndex == 0 {
// maxBlockIndex = -1
//}
//
//if maxBlockIndex > int(currentBlockHeight) {
// return fmt.Errorf("no new blocks to upload. Max index in NeoFS: %d, current height: %d", maxBlockIndex, currentBlockHeight)
//}

//for blockIndex := maxBlockIndex + 1; blockIndex <= int(currentBlockHeight); blockIndex++ {
// blockData, err := fetchBlockData(rpcClient, uint(blockIndex))
// if err != nil {
// return fmt.Errorf("failed to fetch block %d: %w", blockIndex, err)
// }
//
// err = uploadBObjWithSlicer(ctx.Context, clientSDK, *acc, containerID, blockData, attribute, strconv.Itoa(blockIndex), sessionToken)
// if err != nil {
// return fmt.Errorf("failed to upload block %d: %w", blockIndex, err)
// }
//
// if blockIndex%1000 == 0 {
// log.Printf("Successfully uploaded block: %d", blockIndex)
// }
//}

maxBlockIndex, err := fetchMaxBlockIndex(ctx.Context, clientSDK, containerID, acc.PrivateKey(), uint(currentBlockHeight), attribute)
if err != nil {
return fmt.Errorf("failed to fetch max block index from container: %w", err)
}
log.Println("Max block index in NeoFS:", maxBlockIndex)
if maxBlockIndex == 0 {
maxBlockIndex = -1
}

if maxBlockIndex > int(currentBlockHeight) {
return fmt.Errorf("no new blocks to upload. Max index in NeoFS: %d, current height: %d", maxBlockIndex, currentBlockHeight)
}

for blockIndex := maxBlockIndex + 1; blockIndex <= int(currentBlockHeight); blockIndex++ {
blockData, err := fetchBlockData(rpcClient, uint(blockIndex))
if err != nil {
return fmt.Errorf("failed to fetch block %d: %w", blockIndex, err)
}

err = uploadBObjWithSlicer(ctx.Context, clientSDK, *acc, containerID, blockData, attribute, strconv.Itoa(blockIndex), sessionToken)
if err != nil {
return fmt.Errorf("failed to upload block %d: %w", blockIndex, err)
}

if blockIndex%1000 == 0 {
log.Printf("Successfully uploaded block: %d", blockIndex)
}
}

err = updateIndexFiles(ctx, clientSDK, containerID, *acc, uint(currentBlockHeight), indexFileAttribute, attribute)
if err != nil {
Expand Down Expand Up @@ -291,7 +291,6 @@ func updateIndexFiles(ctx *cli.Context, clientSDK *client.Client, containerID ci
}
return
}

blockOids[index-startIndex] = oidBlock
if index%1000 == 0 {
log.Println("Found block OID", index)
Expand Down

0 comments on commit 2938069

Please sign in to comment.