Skip to content

Commit a72acea

Browse files
committed
interfaces: tighten blockPutState interface
Instead of just panicking on unimplemented functions in the disk-based implementation. Issue: KBFS-3679
1 parent 0a40f09 commit a72acea

6 files changed

Lines changed: 197 additions & 69 deletions

File tree

‎go/kbfs/libkbfs/block_put_state_disk.go‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ func (bps *blockPutStateDisk) addNewBlock(
6060
ctx, blockPtr, nil, ReadyBlockData{}, syncedCb)
6161
}
6262

63-
func (bps *blockPutStateDisk) mergeOtherBps(
64-
_ context.Context, other blockPutState) error {
65-
panic("unimplemented")
66-
}
67-
68-
func (bps *blockPutStateDisk) removeOtherBps(
69-
ctx context.Context, other blockPutState) error {
70-
panic("unimplemented")
71-
}
72-
7363
func (bps *blockPutStateDisk) getBlock(
7464
ctx context.Context, blockPtr BlockPointer) (Block, error) {
7565
data, serverHalf, _, err := bps.diskCache.Get(
@@ -105,13 +95,3 @@ func (bps *blockPutStateDisk) getReadyBlockData(
10595
serverHalf: serverHalf,
10696
}, nil
10797
}
108-
109-
func (bps *blockPutStateDisk) deepCopy(
110-
_ context.Context) (blockPutState, error) {
111-
panic("unimplemented")
112-
}
113-
114-
func (bps *blockPutStateDisk) deepCopyWithBlacklist(
115-
_ context.Context, blacklist map[BlockPointer]bool) (blockPutState, error) {
116-
panic("unimplemented")
117-
}

‎go/kbfs/libkbfs/block_put_state_memory.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type blockPutStateMemory struct {
2424
lastBlock BlockPointer
2525
}
2626

27-
var _ blockPutState = (*blockPutStateMemory)(nil)
27+
var _ blockPutStateCopiable = (*blockPutStateMemory)(nil)
2828

2929
func newBlockPutStateMemory(length int) *blockPutStateMemory {
3030
bps := &blockPutStateMemory{}
@@ -72,7 +72,7 @@ func (bps *blockPutStateMemory) oldPtr(
7272
}
7373

7474
func (bps *blockPutStateMemory) mergeOtherBps(
75-
_ context.Context, other blockPutState) error {
75+
_ context.Context, other blockPutStateCopiable) error {
7676
otherMem, ok := other.(*blockPutStateMemory)
7777
if !ok {
7878
return errors.Errorf("Cannot remove other bps of type %T", other)
@@ -85,7 +85,7 @@ func (bps *blockPutStateMemory) mergeOtherBps(
8585
}
8686

8787
func (bps *blockPutStateMemory) removeOtherBps(
88-
ctx context.Context, other blockPutState) error {
88+
ctx context.Context, other blockPutStateCopiable) error {
8989
otherMem, ok := other.(*blockPutStateMemory)
9090
if !ok {
9191
return errors.Errorf("Cannot remove other bps of type %T", other)
@@ -154,7 +154,7 @@ func (bps *blockPutStateMemory) numBlocks() int {
154154
}
155155

156156
func (bps *blockPutStateMemory) deepCopy(
157-
_ context.Context) (blockPutState, error) {
157+
_ context.Context) (blockPutStateCopiable, error) {
158158
newBps := &blockPutStateMemory{}
159159
newBps.blockStates = make(map[BlockPointer]blockState, len(bps.blockStates))
160160
for ptr, bs := range bps.blockStates {
@@ -164,7 +164,8 @@ func (bps *blockPutStateMemory) deepCopy(
164164
}
165165

166166
func (bps *blockPutStateMemory) deepCopyWithBlacklist(
167-
_ context.Context, blacklist map[BlockPointer]bool) (blockPutState, error) {
167+
_ context.Context, blacklist map[BlockPointer]bool) (
168+
blockPutStateCopiable, error) {
168169
newBps := &blockPutStateMemory{}
169170
newLen := len(bps.blockStates) - len(blacklist)
170171
if newLen < 0 {

‎go/kbfs/libkbfs/folder_block_ops.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ const (
5858

5959
type mdToCleanIfUnused struct {
6060
md ReadOnlyRootMetadata
61-
bps blockPutState
61+
bps blockPutStateCopiable
6262
}
6363

6464
type syncInfo struct {
6565
oldInfo BlockInfo
6666
op *syncOp
6767
unrefs []BlockInfo
68-
bps blockPutState
68+
bps blockPutStateCopiable
6969
refBytes uint64
7070
unrefBytes uint64
7171
toCleanIfUnused []mdToCleanIfUnused
@@ -2555,7 +2555,7 @@ type fileSyncState struct {
25552555
// entry, dirtyDe will be nil.
25562556
func (fbo *folderBlockOps) startSyncWrite(ctx context.Context,
25572557
lState *lockState, md *RootMetadata, file path) (
2558-
fblock *FileBlock, bps blockPutState, syncState fileSyncState,
2558+
fblock *FileBlock, bps blockPutStateCopiable, syncState fileSyncState,
25592559
dirtyDe *DirEntry, err error) {
25602560
fbo.blockLock.Lock(lState)
25612561
defer fbo.blockLock.Unlock(lState)
@@ -2769,7 +2769,7 @@ func (fbo *folderBlockOps) mergeDirtyEntryWithLBC(
27692769
// })
27702770
func (fbo *folderBlockOps) StartSync(ctx context.Context,
27712771
lState *lockState, md *RootMetadata, file path) (
2772-
fblock *FileBlock, bps blockPutState, dirtyDe *DirEntry,
2772+
fblock *FileBlock, bps blockPutStateCopiable, dirtyDe *DirEntry,
27732773
syncState fileSyncState, err error) {
27742774
if jServer, err := GetJournalServer(fbo.config); err == nil {
27752775
jServer.dirtyOpStart(fbo.id())

‎go/kbfs/libkbfs/folder_branch_ops.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5162,7 +5162,7 @@ type cleanupFn func(context.Context, *lockState, []BlockPointer, error)
51625162
func (fbo *folderBranchOps) startSyncLocked(ctx context.Context,
51635163
lState *lockState, md *RootMetadata, node Node, file path) (
51645164
doSync, stillDirty bool, fblock *FileBlock, dirtyDe *DirEntry,
5165-
bps blockPutState, syncState fileSyncState,
5165+
bps blockPutStateCopiable, syncState fileSyncState,
51665166
cleanup cleanupFn, err error) {
51675167
fbo.mdWriterLock.AssertLocked(lState)
51685168

‎go/kbfs/libkbfs/interfaces.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,22 +2738,31 @@ type Chat interface {
27382738
ClearCache()
27392739
}
27402740

2741+
// blockPutState is an interface for keeping track of readied blocks
2742+
// before putting them to the bserver.
27412743
type blockPutState interface {
27422744
addNewBlock(
27432745
ctx context.Context, blockPtr BlockPointer, block Block,
27442746
readyBlockData ReadyBlockData, syncedCb func() error) error
27452747
saveOldPtr(ctx context.Context, oldPtr BlockPointer) error
27462748
oldPtr(ctx context.Context, blockPtr BlockPointer) (BlockPointer, error)
2747-
mergeOtherBps(ctx context.Context, other blockPutState) error
2748-
removeOtherBps(ctx context.Context, other blockPutState) error
27492749
ptrs() []BlockPointer
27502750
getBlock(ctx context.Context, blockPtr BlockPointer) (Block, error)
27512751
getReadyBlockData(
27522752
ctx context.Context, blockPtr BlockPointer) (ReadyBlockData, error)
27532753
synced(blockPtr BlockPointer) error
27542754
numBlocks() int
2755-
deepCopy(ctx context.Context) (blockPutState, error)
2755+
}
2756+
2757+
// blockPutStateCopiable is a more manipulatable interface around
2758+
// `blockPutState`, allowing copying as well as merging/unmerging.
2759+
type blockPutStateCopiable interface {
2760+
blockPutState
2761+
2762+
mergeOtherBps(ctx context.Context, other blockPutStateCopiable) error
2763+
removeOtherBps(ctx context.Context, other blockPutStateCopiable) error
2764+
deepCopy(ctx context.Context) (blockPutStateCopiable, error)
27562765
deepCopyWithBlacklist(
27572766
ctx context.Context, blacklist map[BlockPointer]bool) (
2758-
blockPutState, error)
2767+
blockPutStateCopiable, error)
27592768
}

0 commit comments

Comments
 (0)