Search in sources :

Example 6 with LineFileDocs

use of org.apache.lucene.util.LineFileDocs in project lucene-solr by apache.

the class TestNRTReplication method testCrashPrimary2.

// Crash primary and then restart it
@Nightly
public void testCrashPrimary2() throws Exception {
    Path path1 = createTempDir("1");
    NodeProcess primary = startNode(-1, 0, path1, -1, true);
    Path path2 = createTempDir("2");
    NodeProcess replica = startNode(primary.tcpPort, 1, path2, -1, true);
    sendReplicasToPrimary(primary, replica);
    // Index 10 docs into primary:
    LineFileDocs docs = new LineFileDocs(random());
    try (Connection c = new Connection(primary.tcpPort)) {
        c.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
        for (int i = 0; i < 10; i++) {
            Document doc = docs.nextDoc();
            primary.addOrUpdateDocument(c, doc, false);
        }
    }
    // Refresh primary, which also pushes to replica:
    long primaryVersion1 = primary.flush(0);
    assertTrue(primaryVersion1 > 0);
    // Wait for replica to sync up:
    waitForVersionAndHits(replica, primaryVersion1, 10);
    primary.commit();
    // Index 10 docs, but crash before replicating or committing:
    try (Connection c = new Connection(primary.tcpPort)) {
        c.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
        for (int i = 0; i < 10; i++) {
            Document doc = docs.nextDoc();
            primary.addOrUpdateDocument(c, doc, false);
        }
    }
    // Crash primary:
    primary.crash();
    // Restart it:
    primary = startNode(-1, 0, path1, -1, true);
    sendReplicasToPrimary(primary, replica);
    // Index 10 more docs
    try (Connection c = new Connection(primary.tcpPort)) {
        c.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
        for (int i = 0; i < 10; i++) {
            Document doc = docs.nextDoc();
            primary.addOrUpdateDocument(c, doc, false);
        }
    }
    long primaryVersion2 = primary.flush(0);
    assertTrue(primaryVersion2 > primaryVersion1);
    // Wait for replica to sync up:
    waitForVersionAndHits(replica, primaryVersion2, 20);
    primary.close();
    replica.close();
}
Also used : Path(java.nio.file.Path) Document(org.apache.lucene.document.Document) LineFileDocs(org.apache.lucene.util.LineFileDocs)

Example 7 with LineFileDocs

use of org.apache.lucene.util.LineFileDocs in project lucene-solr by apache.

the class TestNRTReplication method testReplicaCrashWithCommit.

// Start up, index 10 docs, replicate, commit, crash and restart the replica
@Nightly
public void testReplicaCrashWithCommit() throws Exception {
    Path primaryPath = createTempDir("primary");
    NodeProcess primary = startNode(-1, 0, primaryPath, -1, false);
    Path replicaPath = createTempDir("replica");
    NodeProcess replica = startNode(primary.tcpPort, 1, replicaPath, -1, true);
    sendReplicasToPrimary(primary, replica);
    // Index 10 docs into primary:
    LineFileDocs docs = new LineFileDocs(random());
    try (Connection c = new Connection(primary.tcpPort)) {
        c.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
        for (int i = 0; i < 10; i++) {
            Document doc = docs.nextDoc();
            primary.addOrUpdateDocument(c, doc, false);
        }
    }
    // Refresh primary, which also pushes to replica:
    long primaryVersion1 = primary.flush(0);
    assertTrue(primaryVersion1 > 0);
    // Wait for replica to sync up:
    waitForVersionAndHits(replica, primaryVersion1, 10);
    // Commit and crash replica:
    replica.commit();
    replica.crash();
    // Restart replica:
    replica = startNode(primary.tcpPort, 1, replicaPath, -1, false);
    // On startup the replica searches the last commit:
    assertVersionAndHits(replica, primaryVersion1, 10);
    replica.close();
    primary.close();
}
Also used : Path(java.nio.file.Path) Document(org.apache.lucene.document.Document) LineFileDocs(org.apache.lucene.util.LineFileDocs)

Example 8 with LineFileDocs

use of org.apache.lucene.util.LineFileDocs in project lucene-solr by apache.

the class TestNRTReplication method testReplicateDeleteAllDocuments.

@Nightly
public void testReplicateDeleteAllDocuments() throws Exception {
    Path primaryPath = createTempDir("primary");
    NodeProcess primary = startNode(-1, 0, primaryPath, -1, false);
    Path replicaPath = createTempDir("replica");
    NodeProcess replica = startNode(primary.tcpPort, 1, replicaPath, -1, false);
    // Tell primary current replicas:
    sendReplicasToPrimary(primary, replica);
    // Index 10 docs into primary:
    LineFileDocs docs = new LineFileDocs(random());
    Connection primaryC = new Connection(primary.tcpPort);
    primaryC.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
    for (int i = 0; i < 10; i++) {
        Document doc = docs.nextDoc();
        primary.addOrUpdateDocument(primaryC, doc, false);
    }
    // Nothing in replica index yet
    assertVersionAndHits(replica, 0, 0);
    // Refresh primary, which also pushes to replica:
    long primaryVersion1 = primary.flush(0);
    assertTrue(primaryVersion1 > 0);
    // Wait for replica to show the change
    waitForVersionAndHits(replica, primaryVersion1, 10);
    // Delete all docs from primary
    if (random().nextBoolean()) {
        // Inefficiently:
        for (int id = 0; id < 10; id++) {
            primary.deleteDocument(primaryC, Integer.toString(id));
        }
    } else {
        // Efficiently:
        primary.deleteAllDocuments(primaryC);
    }
    // Replica still shows 10 docs:
    assertVersionAndHits(replica, primaryVersion1, 10);
    // Refresh primary, which also pushes to replica:
    long primaryVersion2 = primary.flush(0);
    assertTrue(primaryVersion2 > primaryVersion1);
    // Wait for replica to show the change
    waitForVersionAndHits(replica, primaryVersion2, 0);
    // Index 10 docs again:
    for (int i = 0; i < 10; i++) {
        Document doc = docs.nextDoc();
        primary.addOrUpdateDocument(primaryC, doc, false);
    }
    // Refresh primary, which also pushes to replica:
    long primaryVersion3 = primary.flush(0);
    assertTrue(primaryVersion3 > primaryVersion2);
    // Wait for replica to show the change
    waitForVersionAndHits(replica, primaryVersion3, 10);
    primaryC.close();
    replica.close();
    primary.close();
}
Also used : Path(java.nio.file.Path) Document(org.apache.lucene.document.Document) LineFileDocs(org.apache.lucene.util.LineFileDocs)

Example 9 with LineFileDocs

use of org.apache.lucene.util.LineFileDocs in project lucene-solr by apache.

the class TestNRTReplication method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Node.globalStartNS = System.nanoTime();
    childTempDir = createTempDir("child");
    docs = new LineFileDocs(random());
}
Also used : LineFileDocs(org.apache.lucene.util.LineFileDocs)

Example 10 with LineFileDocs

use of org.apache.lucene.util.LineFileDocs in project lucene-solr by apache.

the class TestNRTReplication method testCrashPrimary1.

// Crash primary and promote a replica
@Nightly
public void testCrashPrimary1() throws Exception {
    Path path1 = createTempDir("1");
    NodeProcess primary = startNode(-1, 0, path1, -1, true);
    Path path2 = createTempDir("2");
    NodeProcess replica = startNode(primary.tcpPort, 1, path2, -1, true);
    sendReplicasToPrimary(primary, replica);
    // Index 10 docs into primary:
    LineFileDocs docs = new LineFileDocs(random());
    try (Connection c = new Connection(primary.tcpPort)) {
        c.out.writeByte(SimplePrimaryNode.CMD_INDEXING);
        for (int i = 0; i < 10; i++) {
            Document doc = docs.nextDoc();
            primary.addOrUpdateDocument(c, doc, false);
        }
    }
    // Refresh primary, which also pushes to replica:
    long primaryVersion1 = primary.flush(0);
    assertTrue(primaryVersion1 > 0);
    // Wait for replica to sync up:
    waitForVersionAndHits(replica, primaryVersion1, 10);
    // Crash primary:
    primary.crash();
    // Promote replica:
    replica.commit();
    replica.close();
    primary = startNode(-1, 1, path2, -1, false);
    // Should still see 10 docs:
    assertVersionAndHits(primary, primaryVersion1, 10);
    primary.close();
}
Also used : Path(java.nio.file.Path) Document(org.apache.lucene.document.Document) LineFileDocs(org.apache.lucene.util.LineFileDocs)

Aggregations

LineFileDocs (org.apache.lucene.util.LineFileDocs)45 Document (org.apache.lucene.document.Document)27 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)24 Directory (org.apache.lucene.store.Directory)17 Path (java.nio.file.Path)16 IOException (java.io.IOException)9 BytesRef (org.apache.lucene.util.BytesRef)8 Random (java.util.Random)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 ArrayList (java.util.ArrayList)5 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 IntPoint (org.apache.lucene.document.IntPoint)4 RAMDirectory (org.apache.lucene.store.RAMDirectory)4 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Analyzer (org.apache.lucene.analysis.Analyzer)3 DoublePoint (org.apache.lucene.document.DoublePoint)3 Field (org.apache.lucene.document.Field)3 FloatPoint (org.apache.lucene.document.FloatPoint)3 LongPoint (org.apache.lucene.document.LongPoint)3