Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
disk_block_cache_remote: Second pass at strib's PR feedback. Switched…
Browse files Browse the repository at this point in the history
… to binary marshaling everywhere.
  • Loading branch information
jzila committed Oct 30, 2017
1 parent 3d9e721 commit 1654b3d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
12 changes: 5 additions & 7 deletions genprotocol/kbgitkbfs-avdl/disk_block_cache.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
@namespace("kbgitkbfs.1")
protocol DiskBlockCache {

import idl "github.com/keybase/client/go/protocol/keybase1" as keybase1;

enum PrefetchStatus {
NO_PREFETCH_0,
TRIGGERED_PREFETCH_1,
Expand All @@ -21,7 +19,7 @@ protocol DiskBlockCache {
*/
record GetBlockRes {
bytes buf;
string serverHalf;
bytes serverHalf;
PrefetchStatus prefetchStatus;
}

Expand All @@ -36,20 +34,20 @@ protocol DiskBlockCache {
/**
GetBlock gets a block from the disk cache.
*/
GetBlockRes GetBlock(keybase1.TLFID tlfID, string blockID);
GetBlockRes GetBlock(bytes tlfID, bytes blockID);

/**
PutBlock puts a block into the disk cache.
*/
void PutBlock(keybase1.TLFID tlfID, string blockID, bytes buf, string serverHalf);
void PutBlock(bytes tlfID, bytes blockID, bytes buf, bytes serverHalf);

/**
DeleteBlocks deletes a set of blocks from the disk cache.
*/
DeleteBlocksRes DeleteBlocks(array<string> blockIDs);
DeleteBlocksRes DeleteBlocks(array<bytes> blockIDs);

/**
UpdateBlockMetadata updates the metadata for a block in the disk cache.
*/
void UpdateBlockMetadata(string blockID, PrefetchStatus prefetchStatus);
void UpdateBlockMetadata(bytes blockID, PrefetchStatus prefetchStatus);
}
4 changes: 4 additions & 0 deletions kbfscrypto/crypto_key_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func (c publicByte32Container) Data() [32]byte {
return c.data
}

func (c publicByte32Container) Bytes() []byte {
return c.data[:]
}

func (c publicByte32Container) MarshalBinary() (data []byte, err error) {
return c.data[:], nil
}
Expand Down
21 changes: 10 additions & 11 deletions libkbfs/disk_block_cache_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"

"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"github.com/keybase/kbfs/kbfsblock"
"github.com/keybase/kbfs/kbfscrypto"
Expand Down Expand Up @@ -60,14 +59,14 @@ func (dbcr *DiskBlockCacheRemote) Get(ctx context.Context, tlfID tlf.ID,
}()

res, err := dbcr.client.GetBlock(ctx, kbgitkbfs.GetBlockArg{
keybase1.TLFID(tlfID.String()),
blockID.String(),
tlfID.Bytes(),
blockID.Bytes(),
})
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}

serverHalf, err = kbfscrypto.ParseBlockCryptKeyServerHalf(res.ServerHalf)
err = serverHalf.UnmarshalBinary(res.ServerHalf)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
Expand All @@ -86,10 +85,10 @@ func (dbcr *DiskBlockCacheRemote) Put(ctx context.Context, tlfID tlf.ID,
}()

return dbcr.client.PutBlock(ctx, kbgitkbfs.PutBlockArg{
keybase1.TLFID(tlfID.String()),
blockID.String(),
tlfID.Bytes(),
blockID.Bytes(),
buf,
serverHalf.String(),
serverHalf.Bytes(),
})
}

Expand All @@ -103,9 +102,9 @@ func (dbcr *DiskBlockCacheRemote) Delete(ctx context.Context,
dbcr.log.LazyTrace(ctx, "DiskBlockCacheRemote: Delete %s block(s) "+
"done (err=%+v)", numBlocks, err)
}()
blocks := make([]string, 0, len(blockIDs))
blocks := make([][]byte, 0, len(blockIDs))
for _, b := range blockIDs {
blocks = append(blocks, b.String())
blocks = append(blocks, b.Bytes())
}
res, err := dbcr.client.DeleteBlocks(ctx, blocks)
if err != nil {
Expand All @@ -120,8 +119,8 @@ func (dbcr *DiskBlockCacheRemote) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, prefetchStatus PrefetchStatus) error {
return dbcr.client.UpdateBlockMetadata(ctx,
kbgitkbfs.UpdateBlockMetadataArg{
blockID.String(),
kbgitkbfs.PrefetchStatus(prefetchStatus),
blockID.Bytes(),
prefetchStatus.ToProtocol(),
})
}

Expand Down
25 changes: 16 additions & 9 deletions libkbfs/disk_block_cache_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ func (cache *DiskBlockCacheService) GetBlock(ctx context.Context,
return kbgitkbfs.GetBlockRes{},
DiskBlockCacheError{"Disk cache is nil"}
}
tlfID, err := tlf.ParseID(arg.TlfID.String())
tlfID := tlf.ID{}
err := tlfID.UnmarshalBinary(arg.TlfID)
if err != nil {
return kbgitkbfs.GetBlockRes{}, newDiskBlockCacheError(err)
}
blockID, err := kbfsblock.IDFromString(arg.BlockID)
blockID := kbfsblock.ID{}
err = blockID.UnmarshalBinary(arg.BlockID)
if err != nil {
return kbgitkbfs.GetBlockRes{}, newDiskBlockCacheError(err)
}
Expand All @@ -56,7 +58,7 @@ func (cache *DiskBlockCacheService) GetBlock(ctx context.Context,
protocolPrefetchStatus := prefetchStatus.ToProtocol()

return kbgitkbfs.GetBlockRes{
buf, serverHalf.String(), protocolPrefetchStatus,
buf, serverHalf.Bytes(), protocolPrefetchStatus,
}, nil
}

Expand All @@ -68,15 +70,18 @@ func (cache *DiskBlockCacheService) PutBlock(ctx context.Context,
if dbc == nil {
return DiskBlockCacheError{"Disk cache is nil"}
}
tlfID, err := tlf.ParseID(arg.TlfID.String())
tlfID := tlf.ID{}
err := tlfID.UnmarshalBinary(arg.TlfID)
if err != nil {
return newDiskBlockCacheError(err)
}
blockID, err := kbfsblock.IDFromString(arg.BlockID)
blockID := kbfsblock.ID{}
err = blockID.UnmarshalBinary(arg.BlockID)
if err != nil {
return newDiskBlockCacheError(err)
}
serverHalf, err := kbfscrypto.ParseBlockCryptKeyServerHalf(arg.ServerHalf)
serverHalf := kbfscrypto.BlockCryptKeyServerHalf{}
err = serverHalf.UnmarshalBinary(arg.ServerHalf)
if err != nil {
return newDiskBlockCacheError(err)
}
Expand All @@ -90,15 +95,16 @@ func (cache *DiskBlockCacheService) PutBlock(ctx context.Context,
// DeleteBlocks implements the DiskBlockCacheInterface interface for
// DiskBlockCacheService.
func (cache *DiskBlockCacheService) DeleteBlocks(ctx context.Context,
blockIDs []string) (kbgitkbfs.DeleteBlocksRes, error) {
blockIDs [][]byte) (kbgitkbfs.DeleteBlocksRes, error) {
dbc := cache.config.DiskBlockCache()
if dbc == nil {
return kbgitkbfs.DeleteBlocksRes{},
DiskBlockCacheError{"Disk cache is nil"}
}
blocks := make([]kbfsblock.ID, 0, len(blockIDs))
for _, b := range blockIDs {
blockID, err := kbfsblock.IDFromString(b)
blockID := kbfsblock.ID{}
err := blockID.UnmarshalBinary(b)
if err != nil {
return kbgitkbfs.DeleteBlocksRes{}, newDiskBlockCacheError(err)
}
Expand All @@ -119,7 +125,8 @@ func (cache *DiskBlockCacheService) UpdateBlockMetadata(ctx context.Context,
if dbc == nil {
return DiskBlockCacheError{"Disk cache is nil"}
}
blockID, err := kbfsblock.IDFromString(arg.BlockID)
blockID := kbfsblock.ID{}
err := blockID.UnmarshalBinary(arg.BlockID)
if err != nil {
return newDiskBlockCacheError(err)
}
Expand Down
23 changes: 11 additions & 12 deletions protocol/kbgitkbfs/disk_block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package kbgitkbfs1

import (
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
)
Expand Down Expand Up @@ -32,7 +31,7 @@ var PrefetchStatusRevMap = map[PrefetchStatus]string{
// GetCachedBlockRes is the response from GetBlock.
type GetBlockRes struct {
Buf []byte `codec:"buf" json:"buf"`
ServerHalf string `codec:"serverHalf" json:"serverHalf"`
ServerHalf []byte `codec:"serverHalf" json:"serverHalf"`
PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"`
}

Expand All @@ -43,23 +42,23 @@ type DeleteBlocksRes struct {
}

type GetBlockArg struct {
TlfID keybase1.TLFID `codec:"tlfID" json:"tlfID"`
BlockID string `codec:"blockID" json:"blockID"`
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
}

type PutBlockArg struct {
TlfID keybase1.TLFID `codec:"tlfID" json:"tlfID"`
BlockID string `codec:"blockID" json:"blockID"`
Buf []byte `codec:"buf" json:"buf"`
ServerHalf string `codec:"serverHalf" json:"serverHalf"`
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
Buf []byte `codec:"buf" json:"buf"`
ServerHalf []byte `codec:"serverHalf" json:"serverHalf"`
}

type DeleteBlocksArg struct {
BlockIDs []string `codec:"blockIDs" json:"blockIDs"`
BlockIDs [][]byte `codec:"blockIDs" json:"blockIDs"`
}

type UpdateBlockMetadataArg struct {
BlockID string `codec:"blockID" json:"blockID"`
BlockID []byte `codec:"blockID" json:"blockID"`
PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"`
}

Expand All @@ -70,7 +69,7 @@ type DiskBlockCacheInterface interface {
// PutBlock puts a block into the disk cache.
PutBlock(context.Context, PutBlockArg) error
// DeleteBlocks deletes a set of blocks from the disk cache.
DeleteBlocks(context.Context, []string) (DeleteBlocksRes, error)
DeleteBlocks(context.Context, [][]byte) (DeleteBlocksRes, error)
// UpdateBlockMetadata updates the metadata for a block in the disk cache.
UpdateBlockMetadata(context.Context, UpdateBlockMetadataArg) error
}
Expand Down Expand Up @@ -164,7 +163,7 @@ func (c DiskBlockCacheClient) PutBlock(ctx context.Context, __arg PutBlockArg) (
}

// DeleteBlocks deletes a set of blocks from the disk cache.
func (c DiskBlockCacheClient) DeleteBlocks(ctx context.Context, blockIDs []string) (res DeleteBlocksRes, err error) {
func (c DiskBlockCacheClient) DeleteBlocks(ctx context.Context, blockIDs [][]byte) (res DeleteBlocksRes, err error) {
__arg := DeleteBlocksArg{BlockIDs: blockIDs}
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.DeleteBlocks", []interface{}{__arg}, &res)
return
Expand Down

0 comments on commit 1654b3d

Please sign in to comment.