-
Notifications
You must be signed in to change notification settings - Fork 624
Make FieldIndex an AutoValue #3147
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
Changes from all commits
38bb22e
641b8d6
e59daed
e463795
2c52df2
a75fb63
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 |
---|---|---|
|
@@ -94,13 +94,15 @@ public void start() { | |
.forEach( | ||
row -> { | ||
try { | ||
int indexId = row.getInt(0); | ||
String collectionGroup = row.getString(1); | ||
List<FieldIndex.Segment> segments = | ||
serializer.decodeFieldIndexSegments(Index.parseFrom(row.getBlob(2))); | ||
SnapshotVersion updateTime = | ||
new SnapshotVersion(new Timestamp(row.getLong(3), row.getInt(4))); | ||
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. Seconds are stored in SQLite as 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. INTEGER means non-floating number of any storage size for SQLite: https://www.sqlite.org/datatype3.html |
||
|
||
FieldIndex fieldIndex = | ||
serializer.decodeFieldIndex( | ||
row.getString(1), | ||
row.getInt(0), | ||
Index.parseFrom(row.getBlob(2)), | ||
row.getInt(3), | ||
row.getInt(4)); | ||
FieldIndex.create(indexId, collectionGroup, segments, updateTime); | ||
memoizeIndex(fieldIndex); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw fail("Failed to decode index: " + e); | ||
|
@@ -146,7 +148,9 @@ public void addFieldIndex(FieldIndex index) { | |
hardAssert(started, "IndexManager not started"); | ||
|
||
int nextIndexId = memoizedMaxId + 1; | ||
index = index.withIndexId(nextIndexId); | ||
index = | ||
FieldIndex.create( | ||
nextIndexId, index.getCollectionGroup(), index.getSegments(), index.getUpdateTime()); | ||
|
||
db.execute( | ||
"INSERT INTO index_configuration (" | ||
|
@@ -157,7 +161,7 @@ public void addFieldIndex(FieldIndex index) { | |
+ "update_time_nanos) VALUES(?, ?, ?, ?, ?)", | ||
nextIndexId, | ||
index.getCollectionGroup(), | ||
encodeFieldIndex(index), | ||
encodeSegments(index), | ||
index.getUpdateTime().getTimestamp().getSeconds(), | ||
index.getUpdateTime().getTimestamp().getNanoseconds()); | ||
|
||
|
@@ -188,7 +192,7 @@ private void updateFieldIndex(FieldIndex index) { | |
+ "update_time_nanos) VALUES(?, ?, ?, ?, ?)", | ||
index.getIndexId(), | ||
index.getCollectionGroup(), | ||
encodeFieldIndex(index), | ||
encodeSegments(index), | ||
index.getUpdateTime().getTimestamp().getSeconds(), | ||
index.getUpdateTime().getTimestamp().getNanoseconds()); | ||
|
||
|
@@ -292,7 +296,11 @@ private FieldIndex getPostUpdateIndex(FieldIndex baseIndex, SnapshotVersion newR | |
if (baseIndex.getUpdateTime().compareTo(newReadTime) > 0) { | ||
return baseIndex; | ||
} else { | ||
return baseIndex.withUpdateTime(newReadTime); | ||
return FieldIndex.create( | ||
baseIndex.getIndexId(), | ||
baseIndex.getCollectionGroup(), | ||
baseIndex.getSegments(), | ||
newReadTime); | ||
} | ||
} | ||
|
||
|
@@ -545,7 +553,7 @@ public FieldIndex getFieldIndex(Target target) { | |
|
||
// Return the index with the most number of segments | ||
return Collections.max( | ||
matchingIndexes, (l, r) -> Integer.compare(l.segmentCount(), r.segmentCount())); | ||
matchingIndexes, (l, r) -> Integer.compare(l.getSegments().size(), r.getSegments().size())); | ||
} | ||
|
||
/** | ||
|
@@ -651,8 +659,8 @@ private boolean isInFilter(Target target, FieldPath fieldPath) { | |
return false; | ||
} | ||
|
||
private byte[] encodeFieldIndex(FieldIndex fieldIndex) { | ||
return serializer.encodeFieldIndex(fieldIndex).toByteArray(); | ||
private byte[] encodeSegments(FieldIndex fieldIndex) { | ||
return serializer.encodeFieldIndexSegments(fieldIndex.getSegments()).toByteArray(); | ||
} | ||
|
||
@VisibleForTesting | ||
|
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.
I think this is an actual bug. I changed the test to catch this.
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.
I don't fully follow. What was the original bug?
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.
It adds an the same index multiple times if it has more than one field.