use of org.neo4j.kernel.impl.core.ReadOnlyDbException in project graphdb by neo4j-attic.
the class AbstractStore method rebuildIdGenerator.
/**
* Rebuilds the {@link IdGenerator} by looping through all records and
* checking if record in use or not.
*
* @throws IOException
* if unable to rebuild the id generator
*/
protected void rebuildIdGenerator() {
if (isReadOnly() && !isBackupSlave()) {
throw new ReadOnlyDbException();
}
logger.fine("Rebuilding id generator for[" + getStorageFileName() + "] ...");
closeIdGenerator();
File file = new File(getStorageFileName() + ".id");
if (file.exists()) {
boolean success = file.delete();
assert success;
}
createIdGenerator(getStorageFileName() + ".id");
openIdGenerator();
FileChannel fileChannel = getFileChannel();
long highId = 1;
long defraggedCount = 0;
try {
long fileSize = fileChannel.size();
int recordSize = getRecordSize();
boolean fullRebuild = true;
if (getConfig() != null) {
String mode = (String) getConfig().get("rebuild_idgenerators_fast");
if (mode != null && mode.toLowerCase().equals("true")) {
fullRebuild = false;
highId = findHighIdBackwards();
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[1]);
// Duplicated code block
LinkedList<Long> freeIdList = new LinkedList<Long>();
if (fullRebuild) {
for (long i = 0; i * recordSize < fileSize && recordSize > 0; i++) {
fileChannel.position(i * recordSize);
fileChannel.read(byteBuffer);
byteBuffer.flip();
byte inUse = byteBuffer.get();
byteBuffer.flip();
nextId();
if ((inUse & 0x1) == Record.NOT_IN_USE.byteValue()) {
freeIdList.add(i);
} else {
highId = i;
while (!freeIdList.isEmpty()) {
freeId(freeIdList.removeFirst());
defraggedCount++;
}
}
}
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to rebuild id generator " + getStorageFileName(), e);
}
setHighId(highId + 1);
if (getConfig() != null) {
String storeDir = (String) getConfig().get("store_dir");
StringLogger msgLog = StringLogger.getLogger(storeDir);
msgLog.logMessage(getStorageFileName() + " rebuild id generator, highId=" + getHighId() + " defragged count=" + defraggedCount, true);
}
logger.fine("[" + getStorageFileName() + "] high id=" + getHighId() + " (defragged=" + defraggedCount + ")");
closeIdGenerator();
openIdGenerator();
}
use of org.neo4j.kernel.impl.core.ReadOnlyDbException in project neo4j-mobile-android by neo4j-contrib.
the class AbstractStore method rebuildIdGenerator.
/**
* Rebuilds the {@link IdGenerator} by looping through all records and
* checking if record in use or not.
*
* @throws IOException
* if unable to rebuild the id generator
*/
@Override
protected void rebuildIdGenerator() {
if (isReadOnly() && !isBackupSlave()) {
throw new ReadOnlyDbException();
}
logger.fine("Rebuilding id generator for[" + getStorageFileName() + "] ...");
closeIdGenerator();
File file = new File(getStorageFileName() + ".id");
if (file.exists()) {
boolean success = file.delete();
assert success;
}
createIdGenerator(getStorageFileName() + ".id");
openIdGenerator();
FileChannel fileChannel = getFileChannel();
long highId = 1;
long defraggedCount = 0;
try {
long fileSize = fileChannel.size();
int recordSize = getRecordSize();
boolean fullRebuild = true;
if (getConfig() != null) {
String mode = (String) getConfig().get("rebuild_idgenerators_fast");
if (mode != null && mode.toLowerCase().equals("true")) {
fullRebuild = false;
highId = findHighIdBackwards();
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[1]);
// Duplicated code block
LinkedList<Long> freeIdList = new LinkedList<Long>();
if (fullRebuild) {
for (long i = 0; i * recordSize < fileSize && recordSize > 0; i++) {
fileChannel.position(i * recordSize);
fileChannel.read(byteBuffer);
byteBuffer.flip();
byte inUse = byteBuffer.get();
byteBuffer.flip();
nextId();
if ((inUse & 0x1) == Record.NOT_IN_USE.byteValue()) {
freeIdList.add(i);
} else {
highId = i;
while (!freeIdList.isEmpty()) {
freeId(freeIdList.removeFirst());
defraggedCount++;
}
}
}
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to rebuild id generator " + getStorageFileName(), e);
}
setHighId(highId + 1);
if (getConfig() != null) {
String storeDir = (String) getConfig().get("store_dir");
StringLogger msgLog = StringLogger.getLogger(storeDir);
msgLog.logMessage(getStorageFileName() + " rebuild id generator, highId=" + getHighId() + " defragged count=" + defraggedCount, true);
}
logger.fine("[" + getStorageFileName() + "] high id=" + getHighId() + " (defragged=" + defraggedCount + ")");
closeIdGenerator();
openIdGenerator();
}
use of org.neo4j.kernel.impl.core.ReadOnlyDbException in project neo4j-mobile-android by neo4j-contrib.
the class NioNeoDbPersistenceSource method createTransaction.
public NeoStoreTransaction createTransaction(XaConnection connection) {
if (xaDs.isReadOnly()) {
throw new ReadOnlyDbException();
}
NeoStoreTransaction result = ((NeoStoreXaConnection) connection).getWriteTransaction();
// This is not a very good solution. The XaConnection is only used when
// delisting/releasing the nioneo xa resource. Maybe it should be stored
// outside the ResourceConnection interface?
result.setXaConnection(connection);
return result;
}
Aggregations