fix: events are added to wrong partition
The writerCache in DataStore did not use the partitionId in its cache key. Therefore the cache could return the wrong writer and events were written to the wrong partition. Fixed by changing the cache key.
This commit is contained in:
@@ -61,6 +61,48 @@ public class DataStore implements AutoCloseable {
|
||||
|
||||
public static Tag TAG_ALL_DOCS = null;
|
||||
|
||||
private static final class PartitionedTagsCacheKey {
|
||||
private final Tags tags;
|
||||
private final ParititionId partitionId;
|
||||
|
||||
public PartitionedTagsCacheKey(final Tags tags, final ParititionId partitionId) {
|
||||
super();
|
||||
this.tags = tags;
|
||||
this.partitionId = partitionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((partitionId == null) ? 0 : partitionId.hashCode());
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final PartitionedTagsCacheKey other = (PartitionedTagsCacheKey) obj;
|
||||
if (partitionId == null) {
|
||||
if (other.partitionId != null)
|
||||
return false;
|
||||
} else if (!partitionId.equals(other.partitionId))
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private final PartitionPersistentMap<Long, Doc, Doc> docIdToDoc;
|
||||
|
||||
private final PartitionPersistentMap<Tags, Long, Long> tagsToDocId;
|
||||
@@ -73,7 +115,7 @@ public class DataStore implements AutoCloseable {
|
||||
// easily.
|
||||
private final HotEntryCache<Long, Doc> docIdToDocCache = new HotEntryCache<>(Duration.ofMinutes(30), 100_000);
|
||||
|
||||
private final HotEntryCache<Tags, PdbWriter> writerCache;
|
||||
private final HotEntryCache<PartitionedTagsCacheKey, PdbWriter> writerCache;
|
||||
|
||||
private final PartitionDiskStore diskStorage;
|
||||
private final Path storageBasePath;
|
||||
@@ -328,7 +370,8 @@ public class DataStore implements AutoCloseable {
|
||||
|
||||
private PdbWriter getWriter(final ParititionId partitionId, final Tags tags) throws ReadException, WriteException {
|
||||
|
||||
return writerCache.putIfAbsent(tags, t -> getWriterInternal(partitionId, tags));
|
||||
final PartitionedTagsCacheKey cacheKey = new PartitionedTagsCacheKey(tags, partitionId);
|
||||
return writerCache.putIfAbsent(cacheKey, t -> getWriterInternal(partitionId, tags));
|
||||
}
|
||||
|
||||
// visible for test
|
||||
|
||||
@@ -92,4 +92,23 @@ public class PartitionLongList implements Iterable<ParititionId> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final ParititionId partitionId : lists.keySet()) {
|
||||
builder.append(partitionId.getPartitionId());
|
||||
builder.append(": values=");
|
||||
final LongList longList = lists.get(partitionId);
|
||||
builder.append(longList.size());
|
||||
if (longList.size() > 0) {
|
||||
builder.append(" first=");
|
||||
builder.append(longList.get(0));
|
||||
builder.append(" last=");
|
||||
builder.append(longList.get(longList.size() - 1));
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user