use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class LocalPaginatedStorageRestoreTx method testSimpleRestore.
public void testSimpleRestore() throws Exception {
List<Future<Void>> futures = new ArrayList<Future<Void>>();
baseDocumentTx.declareIntent(new OIntentMassiveInsert());
for (int i = 0; i < 8; i++) futures.add(executorService.submit(new DataPropagationTask()));
for (Future<Void> future : futures) future.get();
Thread.sleep(1500);
copyDataFromTestWithoutClose();
OStorage storage = baseDocumentTx.getStorage();
baseDocumentTx.close();
storage.close();
testDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDir.getAbsolutePath() + "/testLocalPaginatedStorageRestoreFromTx");
testDocumentTx.open("admin", "admin");
testDocumentTx.close();
ODatabaseCompare databaseCompare = new ODatabaseCompare(testDocumentTx.getURL(), baseDocumentTx.getURL(), "admin", "admin", new OCommandOutputListener() {
@Override
public void onMessage(String text) {
System.out.println(text);
}
});
databaseCompare.setCompareIndexMetadata(true);
Assert.assertTrue(databaseCompare.compare());
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class StorageBackupMTStateTest method testRun.
public void testRun() throws Exception {
String buildDirectory = System.getProperty("buildDirectory", ".");
String dbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName();
System.out.println("Clean up old data");
OFileUtils.deleteRecursively(new File(dbDirectory));
final String backedUpDbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName() + "BackUp";
OFileUtils.deleteRecursively(new File(backedUpDbDirectory));
backupDir = new File(buildDirectory, StorageBackupMTStateTest.class.getSimpleName() + "BackupDir");
OFileUtils.deleteRecursively(backupDir);
if (!backupDir.exists())
Assert.assertTrue(backupDir.mkdirs());
dbURL = "plocal:" + dbDirectory;
System.out.println("Create database");
ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
databaseDocumentTx.create();
System.out.println("Create schema");
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
for (int i = 0; i < 3; i++) {
createClass(schema);
}
databaseDocumentTx.close();
pool = new OPartitionedDatabasePool(dbURL, "admin", "admin");
System.out.println("Start data modification");
final ExecutorService executor = Executors.newFixedThreadPool(5);
final ScheduledExecutorService backupExecutor = Executors.newSingleThreadScheduledExecutor();
final ScheduledExecutorService classCreatorExecutor = Executors.newSingleThreadScheduledExecutor();
final ScheduledExecutorService classDeleterExecutor = Executors.newSingleThreadScheduledExecutor();
classDeleterExecutor.scheduleWithFixedDelay(new ClassDeleter(), 10, 10, TimeUnit.MINUTES);
backupExecutor.scheduleWithFixedDelay(new IncrementalBackupThread(), 5, 5, TimeUnit.MINUTES);
classCreatorExecutor.scheduleWithFixedDelay(new ClassAdder(), 7, 5, TimeUnit.MINUTES);
List<Future<Void>> futures = new ArrayList<Future<Void>>();
futures.add(executor.submit(new NonTxInserter()));
futures.add(executor.submit(new NonTxInserter()));
futures.add(executor.submit(new TxInserter()));
futures.add(executor.submit(new TxInserter()));
futures.add(executor.submit(new RecordsDeleter()));
int k = 0;
while (k < 180) {
Thread.sleep(30 * 1000);
k++;
System.out.println(k * 0.5 + " minutes...");
}
stop = true;
System.out.println("Stop backup");
backupExecutor.shutdown();
System.out.println("Stop class creation/deletion");
classCreatorExecutor.shutdown();
classDeleterExecutor.shutdown();
backupExecutor.awaitTermination(15, TimeUnit.MINUTES);
classCreatorExecutor.awaitTermination(15, TimeUnit.MINUTES);
classDeleterExecutor.awaitTermination(15, TimeUnit.MINUTES);
System.out.println("Stop data threads");
for (Future<Void> future : futures) future.get();
System.out.println("All threads are stopped");
pool.close();
System.out.println("Final incremental backup");
databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.incrementalBackup(backupDir.getAbsolutePath());
OStorage storage = databaseDocumentTx.getStorage();
databaseDocumentTx.close();
storage.close(true, false);
System.out.println("Create backup database");
final ODatabaseDocumentTx backedUpDb = new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
backedUpDb.create(backupDir.getAbsolutePath());
final OStorage backupStorage = backedUpDb.getStorage();
backedUpDb.close();
backupStorage.close(true, false);
System.out.println("Compare databases");
final ODatabaseCompare compare = new ODatabaseCompare("plocal:" + dbDirectory, "plocal:" + backedUpDbDirectory, "admin", "admin", new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
});
Assert.assertTrue(compare.compare());
System.out.println("Drop databases and backup directory");
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.drop();
backedUpDb.open("admin", "admin");
backedUpDb.drop();
OFileUtils.deleteRecursively(backupDir);
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class LocalPaginatedStorageIncrementalSync method assertDatabasesAreInSynch.
private void assertDatabasesAreInSynch() throws Exception {
originalDB.activateOnCurrentThread();
final long originalRecords = originalDB.countClass("Sample");
syncDB.activateOnCurrentThread();
final long syncRecords = syncDB.countClass("Sample");
Assert.assertEquals(originalRecords, syncRecords);
originalDB.activateOnCurrentThread();
OSchema schema = originalDB.getMetadata().getSchema();
OClass clazz = schema.getClass("Sample");
int[] clusterIds = clazz.getClusterIds();
for (int clusterId : clusterIds) {
final OStorage originalStorage = originalDB.getStorage();
final OStorage syncedStorage = syncDB.getStorage();
final long[] db1Range = originalStorage.getClusterDataRange(clusterId);
final long[] db2Range = syncedStorage.getClusterDataRange(clusterId);
Assert.assertEquals(db1Range, db2Range);
final ORecordId rid = new ORecordId(clusterId);
OPhysicalPosition[] physicalPositions = originalStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
while (physicalPositions.length > 0) {
for (OPhysicalPosition physicalPosition : physicalPositions) {
rid.setClusterPosition(physicalPosition.clusterPosition);
final ORawBuffer originalBuffer = originalStorage.readRecord(rid, null, true, false, null).getResult();
final ORawBuffer syncBuffer = syncedStorage.readRecord(rid, null, true, false, null).getResult();
Assert.assertEquals(originalBuffer.recordType, syncBuffer.recordType);
Assert.assertEquals(originalBuffer.version, syncBuffer.version);
Assert.assertEquals(originalBuffer.buffer, syncBuffer.buffer);
}
physicalPositions = originalStorage.higherPhysicalPositions(clusterId, physicalPositions[physicalPositions.length - 1]);
}
}
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OrientGraphFactoryEncryptionTest method verifyDatabaseEncryption.
public void verifyDatabaseEncryption(OrientGraphFactory fc) {
ODatabaseDocumentTx db = fc.getDatabase();
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
db = fc.getDatabase();
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = fc.getDatabase();
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db = fc.getDatabase();
db.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db = fc.getDatabase();
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = fc.getDatabase();
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OServer method openDatabase.
public ODatabaseDocumentTx openDatabase(final ODatabaseDocumentTx database, final String user, final String password, final ONetworkProtocolData data, final boolean iBypassAccess) {
final OStorage storage = database.getStorage();
if (database.isClosed()) {
if (storage instanceof ODirectMemoryStorage && !storage.exists()) {
try {
database.create();
} catch (OStorageException e) {
}
} else {
if (iBypassAccess) {
// BYPASS SECURITY
openDatabaseBypassingSecurity(database, data, user);
} else {
// TRY WITH SERVER'S AUTHENTICATION
OServerUserConfiguration serverUser = serverLogin(user, password, "database.passthrough");
if (serverUser != null) {
// Why do we use the returned serverUser name instead of just passing-in user?
// Because in some security implementations the user is embedded inside a ticket of some kind
// that must be decrypted to retrieve the actual user identity. If serverLogin() is successful,
// that user identity is returned.
// SERVER AUTHENTICATED, BYPASS SECURITY
openDatabaseBypassingSecurity(database, data, serverUser.name);
} else {
// TRY DATABASE AUTHENTICATION
database.open(user, password);
if (data != null) {
data.serverUser = false;
data.serverUsername = null;
}
}
}
}
}
return database;
}
Aggregations