Search in sources :

Example 1 with Keyspace

use of com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace in project esop by instaclustr.

the class ManifestComponentsTest method testTableEquality.

@Test
public void testTableEquality() throws Exception {
    Manifest manifest = parseManifest();
    Snapshot snapshot = manifest.getSnapshot();
    Keyspace keyspace = snapshot.getKeyspace("ks1").orElseThrow(IllegalStateException::new);
    Table table = keyspace.getTable("ks1t1").orElseThrow(IllegalStateException::new);
    Table cloned = table.clone();
    assertNotSame(table, cloned);
    assertEquals(table, cloned);
    cloned.add("me-1-big-Data.db", new ManifestEntry(Paths.get("abc/def"), null, Type.FILE, 50, null, null));
    assertNotEquals(table, cloned);
}
Also used : Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) Table(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace.Table) KeyspaceTable(com.instaclustr.esop.impl.KeyspaceTable) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 2 with Keyspace

use of com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace in project esop by instaclustr.

the class ManifestComponentsTest method testSnapshotEquality.

@Test
public void testSnapshotEquality() throws Exception {
    Manifest manifest = parseManifest();
    Snapshot snapshot = manifest.getSnapshot();
    Snapshot cloned = snapshot.clone();
    assertNotSame(cloned, snapshot);
    assertEquals(cloned, snapshot);
    Keyspace ks = new Keyspace(new HashMap<>());
    Table tb = snapshot.getTable("ks1", "ks1t2").orElseThrow(IllegalStateException::new);
    ks.add("t100", tb);
    cloned.add("k100", ks);
    assertNotEquals(snapshot, cloned);
}
Also used : Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) Table(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace.Table) KeyspaceTable(com.instaclustr.esop.impl.KeyspaceTable) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 3 with Keyspace

use of com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace in project esop by instaclustr.

the class ManifestComponentsTest method testKeyspaceEquality.

@Test
public void testKeyspaceEquality() throws Exception {
    Manifest manifest = parseManifest();
    Snapshot snapshot = manifest.getSnapshot();
    Keyspace keyspace = snapshot.getKeyspace("ks1").orElseThrow(IllegalStateException::new);
    Keyspace cloned = keyspace.clone();
    assertNotSame(keyspace, cloned);
    assertEquals(keyspace, cloned);
    cloned.add("newtable", keyspace.getTable("ks1t1").orElseThrow(IllegalStateException::new));
    assertNotEquals(keyspace, cloned);
}
Also used : Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 4 with Keyspace

use of com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace in project esop by instaclustr.

the class ManifestTest method testManifestMethods.

@Test
public void testManifestMethods() throws Exception {
    Manifest[] manifests = prepareDatabase();
    try {
        // schemas across snapshots are not same
        assertNotEquals(manifests[0].getSchemaVersion(), manifests[1].getSchemaVersion());
        assertNotEquals(manifests[1].getSchemaVersion(), manifests[2].getSchemaVersion());
        assertNotEquals(manifests[0].getSchemaVersion(), manifests[2].getSchemaVersion());
        // however, this is true, because tables which are present in both are same
        assertTrue(manifests[0].getSnapshot().hasSameSchemas(manifests[1].getSnapshot()));
        assertTrue(manifests[0].getSnapshot().hasSameSchemas(manifests[2].getSnapshot()));
        assertTrue(manifests[1].getSnapshot().hasSameSchemas(manifests[2].getSnapshot()));
        // second and third snapshot are "same" on schemas even third snapshot has one table more
        // but it is important that same tables are same
        assertTrue(manifests[0].getSnapshot().getKeyspace("ks1").get().hasSameSchema(manifests[1].getSnapshot().getKeyspace("ks1").get()));
        assertTrue(manifests[1].getSnapshot().getKeyspace("ks2").get().hasSameSchema(manifests[2].getSnapshot().getKeyspace("ks2").get()));
        // however, we have altered a schema of k2t2
        assertFalse(manifests[2].getSnapshot().hasSameSchemas(manifests[3].getSnapshot()));
        assertFalse(manifests[2].getSnapshot().getKeyspace("ks2").get().hasSameSchema(manifests[3].getSnapshot().getKeyspace("ks2").get()));
        Keyspace ks2BeforeAlter = manifests[2].getSnapshot().getKeyspace("ks2").get();
        Keyspace ks2AfterAlter = manifests[3].getSnapshot().getKeyspace("ks2").get();
        // TODO - get entities with different schemas
        List<String> tablesWithDifferentSchemas = ks2BeforeAlter.getTablesWithDifferentSchemas(ks2AfterAlter);
        assertFalse(tablesWithDifferentSchemas.isEmpty());
        assertEquals(1, tablesWithDifferentSchemas.size());
        assertEquals("ks2t2", tablesWithDifferentSchemas.get(0));
    } finally {
        try {
            for (Manifest manifest : manifests) {
                waitForOperation(new ClearSnapshotOperation(jmx, new ClearSnapshotOperationRequest(manifest.getSnapshot().getName())));
            }
        } catch (final Exception ex) {
            logger.error("Unable to clear snapshots", ex);
        }
    }
}
Also used : ClearSnapshotOperation(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation) ClearSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation.ClearSnapshotOperationRequest) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) SchemaBuilder.createKeyspace(com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createKeyspace) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 5 with Keyspace

use of com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace in project esop by instaclustr.

the class ManifestTest method testJsonManifest.

@Test
public void testJsonManifest() throws Exception {
    try {
        final List<String> tokens = new CassandraTokens(jmx).act();
        DatabaseEntities databaseEntities = DatabaseEntities.empty();
        // first table
        createTable("ks1", "ks1t1");
        disableAutocompaction("ks1");
        // #1 insert and flush & take snapshot
        insertDataIntoTable("ks1", "ks1t1");
        flush("ks1");
        insertDataIntoTable("ks1", "ks1t1");
        flush("ks1");
        waitForOperation(new TakeSnapshotOperation(jmx, new TakeSnapshotOperationRequest(databaseEntities, "snapshot1"), cassandraVersionProvider));
        // #2 insert and flush & take snapshot
        insertDataIntoTable("ks1", "ks1t1");
        flush("ks1");
        insertDataIntoTable("ks1", "ks1t1");
        flush("ks1");
        waitForOperation(new TakeSnapshotOperation(jmx, new TakeSnapshotOperationRequest(databaseEntities, "snapshot2"), cassandraVersionProvider));
        // second table
        createTable("ks2", "ks2t1");
        disableAutocompaction("ks2");
        // #1 insert and flush & take snapshot
        insertDataIntoTable("ks2", "ks2t1");
        flush("ks2");
        insertDataIntoTable("ks2", "ks2t1");
        flush("ks2");
        waitForOperation(new TakeSnapshotOperation(jmx, new TakeSnapshotOperationRequest(databaseEntities, "snapshot3"), cassandraVersionProvider));
        // parse
        final Snapshots snapshots = Snapshots.parse(cassandraDataDir);
        assertNotNull(snapshots);
        assertFalse(snapshots.isEmpty());
        assertEquals(3, snapshots.size());
        assertTrue(snapshots.get("snapshot1").isPresent());
        assertTrue(snapshots.get("snapshot2").isPresent());
        assertTrue(snapshots.get("snapshot3").isPresent());
        Manifest manifest = new Manifest(snapshots.get("snapshot3").get());
        // manifest itself, but it wont be serialised
        final Path localManifestPath = getLocalManifestPath("snapshot1");
        manifest.setManifest(getManifestAsManifestEntry(localManifestPath));
        // tokens
        manifest.setTokens(tokens);
        final String schemaVersion = new CassandraSchemaVersion(jmx).act();
        manifest.setSchemaVersion(schemaVersion);
        String writtenManifestAsJson = Manifest.write(manifest, objectMapper);
        logger.info(writtenManifestAsJson);
        assertNotNull(writtenManifestAsJson);
        Snapshot snapshot3 = snapshots.get("snapshot3").get();
        Optional<Keyspace> ks2 = snapshot3.getKeyspace("ks2");
        assertTrue(ks2.isPresent());
        assertTrue(ks2.get().containsTable("ks2t1"));
        List<ManifestEntry> ks2t1 = ks2.get().getManifestEntries("ks2t1");
        assertFalse(ks2t1.isEmpty());
        Manifest readManifest = Manifest.read(writtenManifestAsJson, objectMapper);
        assertNotNull(readManifest);
        HashMultimap<String, String> ksAndTables = readManifest.getSnapshot().getKeyspacesAndTables();
        // also system
        assertTrue(ksAndTables.size() > 2);
        assertTrue(ksAndTables.containsEntry("ks1", "ks1t1"));
        assertTrue(ksAndTables.containsEntry("ks2", "ks2t1"));
        HashMultimap<String, String> ksAndTablesWithoutSystem = readManifest.getSnapshot().getKeyspacesAndTables(false);
        assertEquals(2, ksAndTablesWithoutSystem.size());
        assertTrue(ksAndTables.containsEntry("ks1", "ks1t1"));
        assertTrue(ksAndTables.containsEntry("ks2", "ks2t1"));
        snapshots.clear();
        assertTrue(snapshots.isEmpty());
        assertEquals(0, snapshots.size());
    } finally {
        try {
            waitForOperation(new ClearSnapshotOperation(jmx, new ClearSnapshotOperationRequest("snapshot1")));
            waitForOperation(new ClearSnapshotOperation(jmx, new ClearSnapshotOperationRequest("snapshot2")));
            waitForOperation(new ClearSnapshotOperation(jmx, new ClearSnapshotOperationRequest("snapshot3")));
        } catch (final Exception ex) {
            logger.error("Unable to clear snapshots", ex);
        }
    }
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Manifest.getLocalManifestPath(com.instaclustr.esop.impl.Manifest.getLocalManifestPath) Path(java.nio.file.Path) ClearSnapshotOperation(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation) ClearSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation.ClearSnapshotOperationRequest) TakeSnapshotOperation(com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation) TakeSnapshotOperationRequest(com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation.TakeSnapshotOperationRequest) Manifest(com.instaclustr.esop.impl.Manifest) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion) Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Manifest.getManifestAsManifestEntry(com.instaclustr.esop.impl.Manifest.getManifestAsManifestEntry) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) SchemaBuilder.createKeyspace(com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createKeyspace) CassandraTokens(com.instaclustr.esop.impl.interaction.CassandraTokens) Snapshots(com.instaclustr.esop.impl.Snapshots) Test(org.testng.annotations.Test)

Aggregations

Manifest (com.instaclustr.esop.impl.Manifest)5 Keyspace (com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace)5 Test (org.testng.annotations.Test)5 Snapshot (com.instaclustr.esop.impl.Snapshots.Snapshot)4 SchemaBuilder.createKeyspace (com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createKeyspace)2 KeyspaceTable (com.instaclustr.esop.impl.KeyspaceTable)2 ManifestEntry (com.instaclustr.esop.impl.ManifestEntry)2 Table (com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace.Table)2 ClearSnapshotOperation (com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation)2 ClearSnapshotOperationRequest (com.instaclustr.esop.impl.backup.coordination.ClearSnapshotOperation.ClearSnapshotOperationRequest)2 DatabaseEntities (com.instaclustr.esop.impl.DatabaseEntities)1 Manifest.getLocalManifestPath (com.instaclustr.esop.impl.Manifest.getLocalManifestPath)1 Manifest.getManifestAsManifestEntry (com.instaclustr.esop.impl.Manifest.getManifestAsManifestEntry)1 Snapshots (com.instaclustr.esop.impl.Snapshots)1 TakeSnapshotOperation (com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation)1 TakeSnapshotOperationRequest (com.instaclustr.esop.impl.backup.coordination.TakeSnapshotOperation.TakeSnapshotOperationRequest)1 CassandraSchemaVersion (com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)1 CassandraTokens (com.instaclustr.esop.impl.interaction.CassandraTokens)1 Path (java.nio.file.Path)1