2022-09-21 13:52:02 +03:00
package control
import (
2023-03-07 16:38:26 +03:00
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"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"
2022-09-21 13:52:02 +03:00
"github.com/spf13/cobra"
)
2023-12-27 08:20:15 +03:00
const sealFlag = "seal"
2022-09-21 13:52:02 +03:00
var flushCacheCmd = & cobra . Command {
2023-12-27 14:37:22 +03: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 13:52:02 +03:00
}
func flushCache ( cmd * cobra . Command , _ [ ] string ) {
pk := key . Get ( cmd )
2023-12-27 08:20:15 +03:00
seal , _ := cmd . Flags ( ) . GetBool ( sealFlag )
req := & control . FlushCacheRequest { Body : & control . FlushCacheRequest_Body {
Seal : seal ,
} }
2022-10-10 20:58:28 +03:00
req . Body . Shard_ID = getShardIDList ( cmd )
2022-09-21 13:52:02 +03: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 12:20:16 +03:00
commonCmd . ExitOnErr ( cmd , "rpc error: %w" , err )
2022-09-21 13:52:02 +03:00
verifyResponse ( cmd , resp . GetSignature ( ) , resp . GetBody ( ) )
cmd . Println ( "Write-cache has been flushed." )
}
func initControlFlushCacheCmd ( ) {
2022-10-17 18:37:15 +03:00
initControlFlags ( flushCacheCmd )
2022-09-21 13:52:02 +03:00
ff := flushCacheCmd . Flags ( )
2022-10-10 20:58:28 +03:00
ff . StringSlice ( shardIDFlag , nil , "List of shard IDs in base58 encoding" )
2022-10-10 21:14:12 +03:00
ff . Bool ( shardAllFlag , false , "Process all shards" )
2023-12-27 08:20:15 +03:00
ff . Bool ( sealFlag , false , "Writecache will be left in read-only mode after flush completed" )
2022-09-21 13:52:02 +03:00
2022-10-10 21:14:12 +03:00
flushCacheCmd . MarkFlagsMutuallyExclusive ( shardIDFlag , shardAllFlag )
2022-09-21 13:52:02 +03:00
}