ternblocks: refactor to use blockservice package

This commit is contained in:
Miroslav Crnic
2026-03-24 13:18:05 +00:00
parent 0843c1c05c
commit 64db04c3bc
5 changed files with 336 additions and 1165 deletions
+3 -3
View File
@@ -273,7 +273,7 @@ type BlockServiceOpts struct {
StorageClasses []msgs.StorageClass
FailureDomain string
Location msgs.Location
FutureCutoff *time.Duration
EraseCutoff *time.Duration
LogLevel log.LogLevel
RegistryAddress string
Profile bool
@@ -300,8 +300,8 @@ func (procs *ManagedProcesses) StartBlockService(ll *log.Logger, opts *BlockServ
if opts.Addr2 != "" {
args = append(args, "-addr", opts.Addr2)
}
if opts.FutureCutoff != nil {
args = append(args, "-future-cutoff", opts.FutureCutoff.String())
if opts.EraseCutoff != nil {
args = append(args, "-erase-cutoff", opts.EraseCutoff.String())
}
if opts.LogLevel == log.DEBUG {
args = append(args, "-verbose")
+4 -3
View File
@@ -48,6 +48,7 @@ type BlockServiceOptions struct {
MaxConcurrentReads int
FutureCutoff time.Duration
PastCutoff time.Duration
EraseCutoff time.Duration
ReservedCapacityBytes uint64
}
@@ -454,10 +455,10 @@ func (b *BlockService) EraseBlock(blockId msgs.BlockId, cert [8]byte) ([8]byte,
}
now := time.Now()
pastCutoff := now.Add(-b.options.PastCutoff)
eraseCutoff := now.Add(-b.options.EraseCutoff)
blockTime := msgs.TernTime(uint64(blockId)).Time()
if blockTime.After(pastCutoff) {
if blockTime.After(eraseCutoff) {
return proof, msgs.BLOCK_TOO_RECENT_FOR_DELETION
}
@@ -468,7 +469,7 @@ func (b *BlockService) EraseBlock(blockId msgs.BlockId, cert [8]byte) ([8]byte,
blockPath := path.Join(b.localPath, blockId.Path())
b.logger.Debug("deleting block %v at path %v", blockId, blockPath)
err := eraseFileIfExistsAndSyncDir(blockPath)
if err != nil {
if err != nil && !os.IsNotExist(err) {
atomic.AddUint64(&b.IoErrors, 1)
return proof, err
}
@@ -50,6 +50,7 @@ func createTestService(t *testing.T) *BlockService {
BufferSize: 1024 * 1024,
FutureCutoff: time.Minute,
PastCutoff: time.Minute,
EraseCutoff: time.Minute,
}, pool, bsInfo, "dev1")
deadline := time.Now().Add(5 * time.Second)
+326 -1157
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -884,7 +884,7 @@ func (bsv *blockServiceVictim) start(
FailureDomain: bsv.failureDomain,
LogLevel: log.Level(),
RegistryAddress: fmt.Sprintf("127.0.0.1:%d", registryPort),
FutureCutoff: &testBlockFutureCutoff,
EraseCutoff: &testBlockEraseCutoff,
Addr1: fmt.Sprintf("127.0.0.1:%d", port1),
Addr2: fmt.Sprintf("127.0.0.1:%d", port2),
Profile: profile,
@@ -1042,7 +1042,7 @@ func newTestClient(log *log.Logger, registryAddress string, counters *client.Cli
// 0 interval won't do, because otherwise transient files will immediately be
// expired and not picked.
var testTransientDeadlineInterval = 30 * time.Second
var testBlockFutureCutoff = testTransientDeadlineInterval / 2
var testBlockEraseCutoff = testTransientDeadlineInterval / 2
func main() {
overrides := make(cfgOverrides)