use of org.neo4j.kernel.AbstractGraphDatabase in project neo4j-clean-remote-db-addon by jexp.
the class DeleteDatabaseResource method cleanDbDirectory.
private Map<String, Object> cleanDbDirectory(Database database) throws Throwable {
AbstractGraphDatabase graph = database.graph;
String storeDir = graph.getStoreDir();
if (storeDir == null) {
storeDir = config.getString(DATABASE_LOCATION_PROPERTY_KEY);
}
graph.shutdown();
Map<String, Object> result = removeDirectory(storeDir);
// TODO wtf?
// database.graph = new EmbeddedGraphDatabase(storeDir, graph.getKernelData().getConfigParams());
database.start();
return result;
}
use of org.neo4j.kernel.AbstractGraphDatabase in project graphdb by neo4j-attic.
the class OnlineBackup method slaveContextOf.
@SuppressWarnings("unchecked")
private SlaveContext slaveContextOf(GraphDatabaseService graphDb) {
XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
List<Pair<String, Long>> txs = new ArrayList<Pair<String, Long>>();
for (XaDataSource ds : dsManager.getAllRegisteredDataSources()) {
txs.add(Pair.of(ds.getName(), ds.getLastCommittedTxId()));
}
return new SlaveContext(0, 0, txs.toArray(new Pair[0]));
}
use of org.neo4j.kernel.AbstractGraphDatabase in project graphdb by neo4j-attic.
the class TestNode method testLockProblem.
private void testLockProblem(final PropertyContainer entity) throws InterruptedException {
entity.setProperty("key", "value");
final AtomicBoolean gotTheLock = new AtomicBoolean();
Thread thread = new Thread() {
@Override
public void run() {
Transaction tx = getGraphDb().beginTx();
try {
((AbstractGraphDatabase) getGraphDb()).getConfig().getLockManager().getWriteLock(entity);
gotTheLock.set(true);
tx.success();
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
tx.failure();
}
}
};
thread.start();
long endTime = System.currentTimeMillis() + 5000;
while (thread.getState() != State.TERMINATED) {
Thread.sleep(100);
if (System.currentTimeMillis() > endTime) {
break;
}
}
assertFalse(gotTheLock.get());
}
use of org.neo4j.kernel.AbstractGraphDatabase in project graphdb by neo4j-attic.
the class MasterUtil method applyReceivedTransactions.
public static <T> void applyReceivedTransactions(Response<T> response, GraphDatabaseService graphDb, TxHandler txHandler) throws IOException {
XaDataSourceManager dataSourceManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
for (Triplet<String, Long, TxExtractor> tx : IteratorUtil.asIterable(response.transactions())) {
String resourceName = tx.first();
XaDataSource dataSource = dataSourceManager.getXaDataSource(resourceName);
txHandler.accept(tx, dataSource);
ReadableByteChannel txStream = tx.third().extract();
try {
dataSource.applyCommittedTransaction(tx.second(), txStream);
} finally {
txStream.close();
}
}
}
use of org.neo4j.kernel.AbstractGraphDatabase in project graphdb by neo4j-attic.
the class MasterUtil method rotateLogsAndStreamStoreFiles.
public static SlaveContext rotateLogsAndStreamStoreFiles(GraphDatabaseService graphDb, StoreWriter writer) {
File baseDir = getBaseDir(graphDb);
XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
Collection<XaDataSource> sources = dsManager.getAllRegisteredDataSources();
@SuppressWarnings("unchecked") Pair<String, Long>[] appliedTransactions = new Pair[sources.size()];
int i = 0;
for (XaDataSource ds : sources) {
appliedTransactions[i++] = Pair.of(ds.getName(), ds.getLastCommittedTxId());
try {
ds.getXaContainer().getResourceManager().rotateLogicalLog();
} catch (IOException e) {
// TODO: what about error message?
throw new MasterFailureException(e);
}
}
SlaveContext context = new SlaveContext(-1, -1, appliedTransactions);
ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(1024 * 1024);
for (XaDataSource ds : sources) {
try {
ClosableIterable<File> files = ds.listStoreFiles();
try {
for (File storefile : files) {
FileInputStream stream = new FileInputStream(storefile);
try {
writer.write(relativePath(baseDir, storefile), stream.getChannel(), temporaryBuffer, storefile.length() > 0);
} finally {
stream.close();
}
}
} finally {
files.close();
}
} catch (IOException e) {
// TODO: what about error message?
throw new MasterFailureException(e);
}
}
return context;
}
Aggregations