Search in sources :

Example 6 with Location

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());
            }
        }
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Location(org.opensearch.index.translog.Translog.Location) Location(org.opensearch.index.translog.Translog.Location)

Example 7 with Location

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));
        }
    }
}
Also used : Location(org.opensearch.index.translog.Translog.Location)

Aggregations

Location (org.opensearch.index.translog.Translog.Location)7 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 ArrayList (java.util.ArrayList)4 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 InvalidPathException (java.nio.file.InvalidPathException)2 Path (java.nio.file.Path)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.hasToString (org.hamcrest.Matchers.hasToString)2 MissingHistoryOperationsException (org.opensearch.index.engine.MissingHistoryOperationsException)2 Closeable (java.io.Closeable)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1