Search in sources :

Example 1 with CassandraJMXConnectionInfo

use of jmx.org.apache.cassandra.CassandraJMXConnectionInfo in project esop by instaclustr.

the class AbstractBackupTest method liveBackupWithRestoreOnDifferentSchema.

public void liveBackupWithRestoreOnDifferentSchema(final String[][] arguments, final String cassandraVersion) throws Exception {
    Cassandra cassandra = getCassandra(cassandraDir, cassandraVersion);
    cassandra.start();
    waitForCql();
    try (CqlSession session = CqlSession.builder().build()) {
        createTable(session, KEYSPACE, TABLE);
        createTable(session, KEYSPACE_2, TABLE_2);
        // after this, table and table2 will contain 2 rows each
        insert(2, session, new ArrayList<String[]>() {

            {
                add(new String[] { KEYSPACE, TABLE });
                add(new String[] { KEYSPACE_2, TABLE_2 });
            }
        });
        // first backup
        Esop.mainWithoutExit(arguments[0]);
        String firstSchemaVersion = new CassandraSchemaVersion(new CassandraJMXServiceImpl(new CassandraJMXConnectionInfo())).act();
        // create third schema, by this way, Cassandra schema will change
        createTable(session, KEYSPACE_3, TABLE_3);
        waitUntilSchemaChanged(firstSchemaVersion);
        // after this, table and table2 will contain 4 rows each
        // and table3 just 2
        insert(2, session, new ArrayList<String[]>() {

            {
                add(new String[] { KEYSPACE, TABLE });
                add(new String[] { KEYSPACE_2, TABLE_2 });
                add(new String[] { KEYSPACE_3, TABLE_3 });
            }
        });
        // second backup
        Esop.mainWithoutExit(arguments[1]);
        // here we want to restore into first snapshot even though schema has changed, because we added the third table
        // (keep in mind we have not changed schema of any table, we changed Cassandra schema as such)
        // restore into the first backup
        // download
        Esop.mainWithoutExit(arguments[2]);
        // truncate
        Esop.mainWithoutExit(arguments[3]);
        // after truncating, we see that we have truncated just two tables which were
        // in snapshot from snapshot1, not the third one
        dumpTableAndAssertRowCount(session, KEYSPACE, TABLE, 0);
        dumpTableAndAssertRowCount(session, KEYSPACE_2, TABLE_2, 0);
        dumpTableAndAssertRowCount(session, KEYSPACE_3, TABLE_3, 2);
        // import
        Esop.mainWithoutExit(arguments[4]);
        // cleanup
        Esop.mainWithoutExit(arguments[5]);
        // verify
        // here we check that table1 and table2 contains 2 rows each (as we restored it from the first snapshot) and table 3 will contain still 2
        dumpTableAndAssertRowCount(session, KEYSPACE, TABLE, 2);
        dumpTableAndAssertRowCount(session, KEYSPACE_2, TABLE_2, 2);
        dumpTableAndAssertRowCount(session, KEYSPACE_3, TABLE_3, 2);
    } finally {
        cassandra.stop();
        FileUtils.deleteDirectory(cassandraDir);
        deleteDirectory(Paths.get(target("backup1")));
    }
}
Also used : CassandraJMXServiceImpl(jmx.org.apache.cassandra.service.CassandraJMXServiceImpl) CassandraJMXConnectionInfo(jmx.org.apache.cassandra.CassandraJMXConnectionInfo) Cassandra(com.github.nosan.embedded.cassandra.Cassandra) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)

Example 2 with CassandraJMXConnectionInfo

use of jmx.org.apache.cassandra.CassandraJMXConnectionInfo in project esop by instaclustr.

the class AbstractBackupTest method liveBackupWithRestoreOnDifferentTableSchema.

public void liveBackupWithRestoreOnDifferentTableSchema(final String[][] arguments, final String cassandraVersion, final boolean tableAddition) throws Exception {
    Cassandra cassandra = getCassandra(cassandraDir, cassandraVersion);
    cassandra.start();
    waitForCql();
    try (CqlSession session = CqlSession.builder().build()) {
        createTable(session, KEYSPACE, TABLE);
        createTable(session, KEYSPACE_2, TABLE_2);
        // after this, table and table2 will contain 2 rows each
        insert(2, session, new ArrayList<String[]>() {

            {
                add(new String[] { KEYSPACE, TABLE });
                add(new String[] { KEYSPACE_2, TABLE_2 });
            }
        });
        // first backup
        Esop.mainWithoutExit(arguments[0]);
        String firstSchemaVersion = new CassandraSchemaVersion(new CassandraJMXServiceImpl(new CassandraJMXConnectionInfo())).act();
        // create third schema, by this way, Cassandra schema will change
        createTable(session, KEYSPACE_3, TABLE_3);
        waitUntilSchemaChanged(firstSchemaVersion);
        // after this, table and table2 will contain 4 rows each
        // and table3 just 2
        insert(2, session, new ArrayList<String[]>() {

            {
                add(new String[] { KEYSPACE, TABLE });
                add(new String[] { KEYSPACE_2, TABLE_2 });
                add(new String[] { KEYSPACE_3, TABLE_3 });
            }
        });
        // second backup
        Esop.mainWithoutExit(arguments[1]);
        if (tableAddition) {
            addColumnToTable(session, KEYSPACE, TABLE, "newColumn", TEXT);
        } else {
            removeColumnFromTable(session, KEYSPACE, TABLE, TestEntity.NAME);
        }
        // restore into the first snapshot where table1 was without newly added column
        // we effectively restored SSTables on different schema so we expect that values in the new column will be "null"
        // download
        Esop.mainWithoutExit(arguments[2]);
        // truncate
        Esop.mainWithoutExit(arguments[3]);
        // after truncating, we see that we have truncated just two tables which were
        // in snapshot from snapshot1, not the third one
        dumpTableAndAssertRowCount(session, KEYSPACE, TABLE, 0);
        dumpTableAndAssertRowCount(session, KEYSPACE_2, TABLE_2, 0);
        dumpTableAndAssertRowCount(session, KEYSPACE_3, TABLE_3, 2);
        // import
        Esop.mainWithoutExit(arguments[4]);
        // cleanup
        Esop.mainWithoutExit(arguments[5]);
        // verify
        // here we check that table1 and table2 contains 2 rows each (as we restored it from the first snapshot) and table 3 will contain still 2
        dumpTableAndAssertRowCount(session, KEYSPACE, TABLE, 2);
        dumpTableAndAssertRowCount(session, KEYSPACE_2, TABLE_2, 2);
        dumpTableAndAssertRowCount(session, KEYSPACE_3, TABLE_3, 2);
    } finally {
        cassandra.stop();
        FileUtils.deleteDirectory(cassandraDir);
        deleteDirectory(Paths.get(target("backup1")));
    }
}
Also used : CassandraJMXServiceImpl(jmx.org.apache.cassandra.service.CassandraJMXServiceImpl) CassandraJMXConnectionInfo(jmx.org.apache.cassandra.CassandraJMXConnectionInfo) Cassandra(com.github.nosan.embedded.cassandra.Cassandra) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)

Example 3 with CassandraJMXConnectionInfo

use of jmx.org.apache.cassandra.CassandraJMXConnectionInfo in project esop by instaclustr.

the class Esop method init.

static void init(final Runnable command, final CassandraJMXSpec jmxSpec, final HashSpec hashSpec, final OperationRequest operationRequest, final Logger logger, final List<Module> appSpecificModules) {
    final List<Module> modules = new ArrayList<>();
    if (jmxSpec != null) {
        modules.add(new CassandraModule(new CassandraJMXConnectionInfo(jmxSpec)));
    } else {
        modules.add(new AbstractModule() {

            @Override
            protected void configure() {
                bind(StorageServiceMBean.class).toProvider(() -> null);
                bind(Cassandra4StorageServiceMBean.class).toProvider(() -> null);
            }
        });
    }
    modules.add(new JacksonModule());
    modules.add(new OperationsModule());
    modules.add(new StorageModules());
    modules.add(new ExecutorsModule());
    modules.add(new UploadingModule());
    modules.add(new DownloadingModule());
    modules.add(new HashModule(hashSpec));
    modules.addAll(appSpecificModules);
    final Injector injector = Guice.createInjector(// production binds singletons as eager by default
    Stage.PRODUCTION, modules);
    GuiceInjectorHolder.INSTANCE.setInjector(injector);
    injector.injectMembers(command);
    final Validator validator = Validation.byDefaultProvider().configure().constraintValidatorFactory(new GuiceInjectingConstraintValidatorFactory()).buildValidatorFactory().getValidator();
    final Set<ConstraintViolation<OperationRequest>> violations = validator.validate(operationRequest);
    if (!violations.isEmpty()) {
        violations.forEach(violation -> logger.error(violation.getMessage()));
        throw new ValidationException();
    }
}
Also used : UploadingModule(com.instaclustr.esop.impl.backup.BackupModules.UploadingModule) ValidationException(javax.validation.ValidationException) ArrayList(java.util.ArrayList) JacksonModule(com.instaclustr.jackson.JacksonModule) OperationsModule(com.instaclustr.operations.OperationsModule) AbstractModule(com.google.inject.AbstractModule) HashModule(com.instaclustr.esop.impl.hash.HashModule) CassandraModule(com.instaclustr.cassandra.CassandraModule) CassandraJMXConnectionInfo(jmx.org.apache.cassandra.CassandraJMXConnectionInfo) DownloadingModule(com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule) StorageModules(com.instaclustr.esop.guice.StorageModules) ExecutorsModule(com.instaclustr.threading.ExecutorsModule) Injector(com.google.inject.Injector) ConstraintViolation(javax.validation.ConstraintViolation) OperationsModule(com.instaclustr.operations.OperationsModule) Module(com.google.inject.Module) HashModule(com.instaclustr.esop.impl.hash.HashModule) UploadingModule(com.instaclustr.esop.impl.backup.BackupModules.UploadingModule) CassandraModule(com.instaclustr.cassandra.CassandraModule) ExecutorsModule(com.instaclustr.threading.ExecutorsModule) DownloadingModule(com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule) JacksonModule(com.instaclustr.jackson.JacksonModule) AbstractModule(com.google.inject.AbstractModule) GuiceInjectingConstraintValidatorFactory(com.instaclustr.validation.GuiceInjectingConstraintValidatorFactory) Validator(javax.validation.Validator)

Aggregations

CassandraJMXConnectionInfo (jmx.org.apache.cassandra.CassandraJMXConnectionInfo)3 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 Cassandra (com.github.nosan.embedded.cassandra.Cassandra)2 CassandraSchemaVersion (com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)2 CassandraJMXServiceImpl (jmx.org.apache.cassandra.service.CassandraJMXServiceImpl)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 CassandraModule (com.instaclustr.cassandra.CassandraModule)1 StorageModules (com.instaclustr.esop.guice.StorageModules)1 UploadingModule (com.instaclustr.esop.impl.backup.BackupModules.UploadingModule)1 HashModule (com.instaclustr.esop.impl.hash.HashModule)1 DownloadingModule (com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule)1 JacksonModule (com.instaclustr.jackson.JacksonModule)1 OperationsModule (com.instaclustr.operations.OperationsModule)1 ExecutorsModule (com.instaclustr.threading.ExecutorsModule)1 GuiceInjectingConstraintValidatorFactory (com.instaclustr.validation.GuiceInjectingConstraintValidatorFactory)1 ArrayList (java.util.ArrayList)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ValidationException (javax.validation.ValidationException)1