2022-09-21 10:52:02 +00:00
package control
import (
2023-03-07 13:38:26 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
2024-11-07 14:32:10 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
2022-09-21 10:52:02 +00:00
"github.com/spf13/cobra"
)
2023-12-27 05:20:15 +00:00
const sealFlag = "seal"
2022-09-21 10:52:02 +00:00
var flushCacheCmd = & cobra . Command {
2023-12-27 11:37:22 +00:00
Use : "flush-cache" ,
Short : "Flush objects from the write-cache to the main storage" ,
Long : "Flush objects from the write-cache to the main storage" ,
Run : flushCache ,
Deprecated : "Flushing objects from writecache to the main storage is performed by writecache automatically. To flush and seal writecache use `frostfs-cli control shards writecache seal`." ,
2022-09-21 10:52:02 +00:00
}
func flushCache ( cmd * cobra . Command , _ [ ] string ) {
pk := key . Get ( cmd )
2023-12-27 05:20:15 +00:00
seal , _ := cmd . Flags ( ) . GetBool ( sealFlag )
req := & control . FlushCacheRequest { Body : & control . FlushCacheRequest_Body {
Seal : seal ,
} }
2022-10-10 17:58:28 +00:00
req . Body . Shard_ID = getShardIDList ( cmd )
2022-09-21 10:52:02 +00:00
signRequest ( cmd , pk , req )
cli := getClient ( cmd , pk )
var resp * control . FlushCacheResponse
var err error
err = cli . ExecRaw ( func ( client * client . Client ) error {
resp , err = control . FlushCache ( client , req )
return err
} )
2023-01-16 09:20:16 +00:00
commonCmd . ExitOnErr ( cmd , "rpc error: %w" , err )
2022-09-21 10:52:02 +00:00
verifyResponse ( cmd , resp . GetSignature ( ) , resp . GetBody ( ) )
cmd . Println ( "Write-cache has been flushed." )
}
func initControlFlushCacheCmd ( ) {
2022-10-17 15:37:15 +00:00
initControlFlags ( flushCacheCmd )
2022-09-21 10:52:02 +00:00
ff := flushCacheCmd . Flags ( )
2022-10-10 17:58:28 +00:00
ff . StringSlice ( shardIDFlag , nil , "List of shard IDs in base58 encoding" )
2022-10-10 18:14:12 +00:00
ff . Bool ( shardAllFlag , false , "Process all shards" )
2023-12-27 05:20:15 +00:00
ff . Bool ( sealFlag , false , "Writecache will be left in read-only mode after flush completed" )
2022-09-21 10:52:02 +00:00
2022-10-10 18:14:12 +00:00
flushCacheCmd . MarkFlagsMutuallyExclusive ( shardIDFlag , shardAllFlag )
2022-09-21 10:52:02 +00:00
}