Skip to content

Sync -- unexport field #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions x/sync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ const (
// Signifies that we should sync the range [start, end].
// nil [start] means there is no lower bound.
// nil [end] means there is no upper bound.
// [LocalRootID] is the ID of the root of this range in our database.
// If we have no local root for this range, [LocalRootID] is ids.Empty.
// [localRootID] is the ID of the root of this range in our database.
// If we have no local root for this range, [localRootID] is ids.Empty.
type workItem struct {
start []byte
end []byte
priority priority
LocalRootID ids.ID
localRootID ids.ID
}

// TODO danlaine look into using a sync.Pool for workItems
func newWorkItem(localRootID ids.ID, start, end []byte, priority priority) *workItem {
return &workItem{
LocalRootID: localRootID,
localRootID: localRootID,
start: start,
end: end,
priority: priority,
Expand Down Expand Up @@ -239,7 +239,7 @@ func (m *Manager) doWork(ctx context.Context, work *workItem) {
m.unprocessedWorkCond.Signal()
}()

if work.LocalRootID == ids.Empty {
if work.localRootID == ids.Empty {
// the keys in this range have not been downloaded, so get all key/values
m.getAndApplyRangeProof(ctx, work)
} else {
Expand All @@ -253,7 +253,7 @@ func (m *Manager) doWork(ctx context.Context, work *workItem) {
func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) {
rootID := m.getTargetRoot()

if work.LocalRootID == rootID {
if work.localRootID == rootID {
// Start root is the same as the end root, so we're done.
m.completeWorkItem(ctx, work, work.end, rootID, nil)
return
Expand All @@ -262,7 +262,7 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) {
changeProof, err := m.config.Client.GetChangeProof(
ctx,
&pb.SyncGetChangeProofRequest{
StartRootHash: work.LocalRootID[:],
StartRootHash: work.localRootID[:],
EndRootHash: rootID[:],
StartKey: work.start,
EndKey: work.end,
Expand All @@ -287,7 +287,7 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) {
// Add this range as a fresh uncompleted work item to the work heap.
// TODO danlaine send range proof instead of failure notification
if !changeProof.HadRootsInHistory {
work.LocalRootID = ids.Empty
work.localRootID = ids.Empty
m.enqueueWork(work)
return
}
Expand Down Expand Up @@ -629,7 +629,7 @@ func (m *Manager) completeWorkItem(ctx context.Context, work *workItem, largestH
largestHandledKey = work.end
} else {
// the full range wasn't completed, so enqueue a new work item for the range [nextStartKey, workItem.end]
m.enqueueWork(newWorkItem(work.LocalRootID, nextStartKey, work.end, work.priority))
m.enqueueWork(newWorkItem(work.localRootID, nextStartKey, work.end, work.priority))
largestHandledKey = nextStartKey
}
}
Expand Down Expand Up @@ -673,8 +673,8 @@ func (m *Manager) enqueueWork(work *workItem) {

// first item gets higher priority than the second to encourage finished ranges to grow
// rather than start a new range that is not contiguous with existing completed ranges
first := newWorkItem(work.LocalRootID, work.start, mid, medPriority)
second := newWorkItem(work.LocalRootID, mid, work.end, lowPriority)
first := newWorkItem(work.localRootID, work.start, mid, medPriority)
second := newWorkItem(work.localRootID, mid, work.end, lowPriority)

m.unprocessedWork.Insert(first)
m.unprocessedWork.Insert(second)
Expand Down
2 changes: 1 addition & 1 deletion x/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ func Test_Sync_UpdateSyncTarget(t *testing.T) {
item := &workItem{
start: []byte{1},
end: []byte{2},
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}
m.processedWork.Insert(item)

Expand Down
4 changes: 2 additions & 2 deletions x/sync/workheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (wh *workHeap) MergeInsert(item *workItem) {
wh.sortedItems.DescendLessOrEqual(
searchItem,
func(beforeItem *heapItem) bool {
if item.LocalRootID == beforeItem.workItem.LocalRootID && bytes.Equal(beforeItem.workItem.end, item.start) {
if item.localRootID == beforeItem.workItem.localRootID && bytes.Equal(beforeItem.workItem.end, item.start) {
// [beforeItem.start, beforeItem.end] and [item.start, item.end] are
// merged into [beforeItem.start, item.end]
beforeItem.workItem.end = item.end
Expand All @@ -114,7 +114,7 @@ func (wh *workHeap) MergeInsert(item *workItem) {
wh.sortedItems.AscendGreaterOrEqual(
searchItem,
func(afterItem *heapItem) bool {
if item.LocalRootID == afterItem.workItem.LocalRootID && bytes.Equal(afterItem.workItem.start, item.end) {
if item.localRootID == afterItem.workItem.localRootID && bytes.Equal(afterItem.workItem.start, item.end) {
// [item.start, item.end] and [afterItem.start, afterItem.end] are merged into
// [item.start, afterItem.end].
afterItem.workItem.start = item.start
Expand Down
18 changes: 9 additions & 9 deletions x/sync/workheap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_WorkHeap_InnerHeap(t *testing.T) {
start: []byte{1},
end: []byte{2},
priority: lowPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
},
}

Expand All @@ -29,7 +29,7 @@ func Test_WorkHeap_InnerHeap(t *testing.T) {
start: []byte{3},
end: []byte{4},
priority: medPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
},
}

Expand All @@ -38,7 +38,7 @@ func Test_WorkHeap_InnerHeap(t *testing.T) {
start: []byte{5},
end: []byte{6},
priority: highPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
},
}

Expand Down Expand Up @@ -116,19 +116,19 @@ func Test_WorkHeap_Insert_GetWork(t *testing.T) {
start: []byte{4},
end: []byte{5},
priority: lowPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}
mediumPriorityItem := &workItem{
start: []byte{0},
end: []byte{1},
priority: medPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}
highPriorityItem := &workItem{
start: []byte{2},
end: []byte{3},
priority: highPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}
h.Insert(highPriorityItem)
h.Insert(mediumPriorityItem)
Expand Down Expand Up @@ -170,21 +170,21 @@ func Test_WorkHeap_remove(t *testing.T) {
start: []byte{0},
end: []byte{1},
priority: lowPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}

mediumPriorityItem := &workItem{
start: []byte{2},
end: []byte{3},
priority: medPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}

highPriorityItem := &workItem{
start: []byte{4},
end: []byte{5},
priority: highPriority,
LocalRootID: ids.GenerateTestID(),
localRootID: ids.GenerateTestID(),
}

h.Insert(lowPriorityItem)
Expand Down