Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
s/ShardId/SliceIndex/g
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbelvin committed Nov 26, 2018
1 parent ea29983 commit 4c2f53a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 deletions.
10 changes: 5 additions & 5 deletions core/keyserver/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func DecodeToken(token string, msg proto.Message) error {
return proto.Unmarshal(b, msg)
}

// SourceList is a paginator for a map of sources.
// SourceList is a paginator for a list of source slices.
type SourceList []*spb.MapMetadata_SourceSlice

// ParseToken will return the first token if token is "", otherwise it will try to parse the read token.
Expand All @@ -64,7 +64,7 @@ func (s SourceList) First() *rtpb.ReadToken {
return &rtpb.ReadToken{}
}
return &rtpb.ReadToken{
ShardId: 0,
SliceIndex: 0,
LowWatermark: s[0].LowestWatermark,
}
}
Expand All @@ -76,18 +76,18 @@ func (s SourceList) Next(rt *rtpb.ReadToken, lastRow *mutator.LogMessage) *rtpb.
if lastRow != nil {
// There are more items in this shard.
return &rtpb.ReadToken{
ShardId: rt.ShardId,
SliceIndex: rt.SliceIndex,
LowWatermark: lastRow.ID,
}
}

// Advance to the next shard.
nextShard, ok := s.NextShard(rt.ShardId)
nextShard, ok := s.NextShard(rt.SliceIndex)
if !ok {
return &rtpb.ReadToken{} // Encodes to ""
}
return &rtpb.ReadToken{
ShardId: nextShard,
SliceIndex: nextShard,
LowWatermark: s[nextShard].LowestWatermark,
}
}
Expand Down
16 changes: 8 additions & 8 deletions core/keyserver/paginator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestEncodeToken(t *testing.T) {
}

func TestTokenEncodeDecode(t *testing.T) {
rt1 := &rtpb.ReadToken{ShardId: 2, LowWatermark: 5}
rt1 := &rtpb.ReadToken{SliceIndex: 2, LowWatermark: 5}
rt1Token, err := EncodeToken(rt1)
if err != nil {
t.Fatalf("EncodeToken(%v): %v", rt1, err)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestFirst(t *testing.T) {
{LogId: 2, LowestWatermark: 1, HighestWatermark: 10},
{LogId: 3, LowestWatermark: 10, HighestWatermark: 20},
},
want: &rtpb.ReadToken{ShardId: 0, LowWatermark: 1},
want: &rtpb.ReadToken{SliceIndex: 0, LowWatermark: 1},
},
{s: SourceList{}, want: &rtpb.ReadToken{}},
} {
Expand All @@ -102,28 +102,28 @@ func TestNext(t *testing.T) {
{
desc: "first page",
s: a,
rt: &rtpb.ReadToken{ShardId: 0, LowWatermark: 1},
rt: &rtpb.ReadToken{SliceIndex: 0, LowWatermark: 1},
lastRow: &mutator.LogMessage{ID: 6},
want: &rtpb.ReadToken{ShardId: 0, LowWatermark: 6},
want: &rtpb.ReadToken{SliceIndex: 0, LowWatermark: 6},
},
{
desc: "next source",
s: a,
rt: &rtpb.ReadToken{ShardId: 0, LowWatermark: 1},
rt: &rtpb.ReadToken{SliceIndex: 0, LowWatermark: 1},
lastRow: nil,
want: &rtpb.ReadToken{ShardId: 1, LowWatermark: 10},
want: &rtpb.ReadToken{SliceIndex: 1, LowWatermark: 10},
},
{
desc: "last page",
s: a,
rt: &rtpb.ReadToken{ShardId: 1, LowWatermark: 1},
rt: &rtpb.ReadToken{SliceIndex: 1, LowWatermark: 1},
lastRow: nil,
want: &rtpb.ReadToken{},
},
{
desc: "empty",
s: SourceList{},
rt: &rtpb.ReadToken{ShardId: 1, LowWatermark: 1},
rt: &rtpb.ReadToken{SliceIndex: 1, LowWatermark: 1},
lastRow: nil,
want: &rtpb.ReadToken{},
},
Expand Down
4 changes: 2 additions & 2 deletions core/keyserver/readtoken.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import "v1/keytransparency.proto";

// ReadToken can be serialized and handed to users for pagination.
message ReadToken {
// shard_id identifies the source for reading.
int64 shard_id = 1;
// slice_index identifies the source for reading.
int64 slice_index = 1;
// low_watemark identifies the lowest (exclusive) row to return.
int64 low_watermark = 2;
}
Expand Down
75 changes: 40 additions & 35 deletions core/keyserver/readtoken_go_proto/readtoken.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/keyserver/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func (s *Server) ListMutations(ctx context.Context, in *pb.ListMutationsRequest)
}

// Read PageSize + 1 messages from the log to see if there is another page.
high := meta.Sources[rt.ShardId].HighestWatermark
logID := meta.Sources[rt.ShardId].LogId
high := meta.Sources[rt.SliceIndex].HighestWatermark
logID := meta.Sources[rt.SliceIndex].LogId
msgs, err := s.logs.ReadLog(ctx, d.DirectoryID, logID, rt.LowWatermark, high, in.PageSize+1)
if err != nil {
glog.Errorf("ListMutations(): ReadLog(%v, log: %v/(%v, %v], batchSize: %v): %v",
Expand Down
2 changes: 1 addition & 1 deletion core/keyserver/revisions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (m *mutations) ReadLog(ctx context.Context, dirID string,
func MustEncodeToken(t *testing.T, low int64) string {
t.Helper()
rt := &rtpb.ReadToken{
ShardId: 0,
SliceIndex: 0,
LowWatermark: low,
}
token, err := EncodeToken(rt)
Expand Down

0 comments on commit 4c2f53a

Please sign in to comment.