-
Notifications
You must be signed in to change notification settings - Fork 5
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
Introduce ExtendedObjectMetadata, holding Writes #87
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,18 +51,19 @@ type ObjectWrite struct { | |
// GetServerWriteTime returns the server time of the write to the | ||
// given section, or zero if there was none. | ||
func (writes WriteSet) GetServerWriteTime(section string) Timestamp { | ||
return writes.GetWrite(section).ServerTime | ||
wr, _ := writes.GetWrite(section) | ||
return wr.ServerTime | ||
} | ||
|
||
// GetWrite returns the write to the given section, or zero if there | ||
// was none. | ||
func (writes WriteSet) GetWrite(section string) ObjectWrite { | ||
// GetWrite returns the write to the given section, and a bool | ||
// indicating whether there is one. | ||
func (writes WriteSet) GetWrite(section string) (ObjectWrite, bool) { | ||
for _, wr := range writes { | ||
if wr.Section == section { | ||
return wr | ||
return wr, true | ||
} | ||
} | ||
return ObjectWrite{} | ||
return ObjectWrite{}, false | ||
} | ||
|
||
// SetWrite produces a revised slice that includes the given write. | ||
|
@@ -83,7 +84,7 @@ func (writes WriteSet) SetWrite(section string, serverTime Timestamp) WriteSet { | |
func (writes WriteSet) Diff(others WriteSet) WriteSet { | ||
ans := make(WriteSet, 0, len(writes)) | ||
for _, wr := range writes { | ||
owr := others.GetWrite(wr.Section) | ||
owr, _ := others.GetWrite(wr.Section) | ||
if owr == (ObjectWrite{}) { | ||
ans = append(ans, wr) | ||
} | ||
|
@@ -96,8 +97,8 @@ func (writes WriteSet) Diff(others WriteSet) WriteSet { | |
func (writes WriteSet) UnionLeft(others WriteSet) WriteSet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method and the other Union methods are never used (same observation for internal API version types). Do you plan other commits where they are used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I have some vague plans that use various of these. |
||
ans := append(WriteSet{}, writes...) | ||
for _, owr := range others { | ||
wr := ans.GetWrite(owr.Section) | ||
if wr == (ObjectWrite{}) { | ||
_, found := ans.GetWrite(owr.Section) | ||
if !found { | ||
ans = append(ans, owr) | ||
} | ||
} | ||
|
@@ -109,9 +110,13 @@ func (writes WriteSet) UnionLeft(others WriteSet) WriteSet { | |
func (writes WriteSet) UnionMin(others WriteSet) WriteSet { | ||
ans := others.Diff(writes) | ||
for _, wr := range writes { | ||
owr := others.GetWrite(wr.Section) | ||
owr.ServerTime = owr.ServerTime.Min(wr.ServerTime) | ||
ans = append(ans, owr) | ||
owr, found := others.GetWrite(wr.Section) | ||
if found { | ||
owr.ServerTime = owr.ServerTime.Min(wr.ServerTime) | ||
ans = append(ans, owr) | ||
} else { | ||
ans = append(ans, wr) | ||
} | ||
} | ||
return ans | ||
} | ||
|
@@ -121,9 +126,13 @@ func (writes WriteSet) UnionMin(others WriteSet) WriteSet { | |
func (writes WriteSet) UnionMax(others WriteSet) WriteSet { | ||
ans := others.Diff(writes) | ||
for _, wr := range writes { | ||
owr := others.GetWrite(wr.Section) | ||
owr.ServerTime = owr.ServerTime.Max(wr.ServerTime) | ||
ans = append(ans, owr) | ||
owr, found := others.GetWrite(wr.Section) | ||
if found { | ||
owr.ServerTime = owr.ServerTime.Max(wr.ServerTime) | ||
ans = append(ans, owr) | ||
} else { | ||
ans = append(ans, wr) | ||
} | ||
} | ||
return ans | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other nit, but the following check could use the bool variable.