use of org.opensearch.index.translog.Translog.Location in project OpenSearch by opensearch-project.
the class TranslogTests method testLocationHashCodeEquals.
public void testLocationHashCodeEquals() throws IOException {
List<Translog.Location> locations = new ArrayList<>();
List<Translog.Location> locations2 = new ArrayList<>();
int translogOperations = randomIntBetween(10, 100);
try (Translog translog2 = create(createTempDir())) {
for (int op = 0; op < translogOperations; op++) {
locations.add(translog.add(new Translog.Index("test", "" + op, op, primaryTerm.get(), Integer.toString(op).getBytes(Charset.forName("UTF-8")))));
locations2.add(translog2.add(new Translog.Index("test", "" + op, op, primaryTerm.get(), Integer.toString(op).getBytes(Charset.forName("UTF-8")))));
}
int iters = randomIntBetween(10, 100);
for (int i = 0; i < iters; i++) {
Translog.Location location = RandomPicks.randomFrom(random(), locations);
for (Translog.Location loc : locations) {
if (loc == location) {
assertTrue(loc.equals(location));
assertEquals(loc.hashCode(), location.hashCode());
} else {
assertFalse(loc.equals(location));
}
}
for (int j = 0; j < translogOperations; j++) {
assertTrue(locations.get(j).equals(locations2.get(j)));
assertEquals(locations.get(j).hashCode(), locations2.get(j).hashCode());
}
}
}
}
use of org.opensearch.index.translog.Translog.Location in project OpenSearch by opensearch-project.
the class TranslogTests method testSyncUpTo.
public void testSyncUpTo() throws IOException {
int translogOperations = randomIntBetween(10, 100);
int count = 0;
for (int op = 0; op < translogOperations; op++) {
int seqNo = ++count;
final Translog.Location location = translog.add(new Translog.Index("test", "" + op, seqNo, primaryTerm.get(), Integer.toString(seqNo).getBytes(Charset.forName("UTF-8"))));
if (randomBoolean()) {
assertTrue("at least one operation pending", translog.syncNeeded());
assertTrue("this operation has not been synced", translog.ensureSynced(location));
// we are the last location so everything should be synced
assertFalse("the last call to ensureSycned synced all previous ops", translog.syncNeeded());
seqNo = ++count;
translog.add(new Translog.Index("test", "" + op, seqNo, primaryTerm.get(), Integer.toString(seqNo).getBytes(Charset.forName("UTF-8"))));
assertTrue("one pending operation", translog.syncNeeded());
// not syncing now
assertFalse("this op has been synced before", translog.ensureSynced(location));
assertTrue("we only synced a previous operation yet", translog.syncNeeded());
}
if (rarely()) {
translog.rollGeneration();
// not syncing now
assertFalse("location is from a previous translog - already synced", translog.ensureSynced(location));
assertFalse("no sync needed since no operations in current translog", translog.syncNeeded());
}
if (randomBoolean()) {
translog.sync();
assertFalse("translog has been synced already", translog.ensureSynced(location));
}
}
}
Aggregations