use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method getRecordIterator.
@Override
public SearchingRecordIterator getRecordIterator(String tableName, byte[] mustStartWith, byte[] startSearchingAt, DatabaseSession databaseSession, boolean keysOnly) throws BimserverLockConflictException, BimserverDatabaseException {
Cursor cursor = null;
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
BerkeleySearchingRecordIterator berkeleySearchingRecordIterator = new BerkeleySearchingRecordIterator(cursor, this, cursorCounter.incrementAndGet(), mustStartWith, startSearchingAt, keysOnly);
if (MONITOR_CURSOR_STACK_TRACES) {
openCursors.put(berkeleySearchingRecordIterator.getCursorId(), new Exception().getStackTrace());
}
return berkeleySearchingRecordIterator;
} catch (BimserverLockConflictException e) {
if (cursor != null) {
try {
cursor.close();
throw e;
} catch (DatabaseException e1) {
LOGGER.error("", e1);
}
}
} catch (DatabaseException e1) {
LOGGER.error("", e1);
}
return null;
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method storeNoOverwrite.
@Override
public void storeNoOverwrite(String tableName, byte[] key, byte[] value, int index, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException, BimserverConcurrentModificationDatabaseException {
DatabaseEntry dbKey = new DatabaseEntry(key);
DatabaseEntry dbValue = new DatabaseEntry(value, index, length);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
OperationStatus putNoOverwrite = tableWrapper.getDatabase().putNoOverwrite(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
if (putNoOverwrite == OperationStatus.KEYEXIST) {
// TODO temporary test
tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
ByteBuffer keyBuffer = ByteBuffer.wrap(key);
if (key.length == 16) {
int pid = keyBuffer.getInt();
long oid = keyBuffer.getLong();
int rid = -keyBuffer.getInt();
LOGGER.warn("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid + ", " + databaseSession.getEClassForOid(oid).getName());
throw new BimserverConcurrentModificationDatabaseException("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid);
} else {
LOGGER.warn("Key exists");
// throw new BimserverConcurrentModificationDatabaseException("Key exists: " );
}
}
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException("", e);
}
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class BerkeleySearchingRecordIterator method next.
@Override
public Record next() throws BimserverLockConflictException {
if (nextStartSearchingAt != null) {
return getFirstNext(nextStartSearchingAt);
}
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
if (onlyKeys) {
value.setPartial(0, 0, true);
}
try {
OperationStatus next = cursor.getNext(key, value, LockMode.DEFAULT);
if (next == OperationStatus.SUCCESS) {
byte[] firstBytes = new byte[mustStartWith.length];
System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
if (Arrays.equals(firstBytes, mustStartWith)) {
return new BerkeleyRecord(key, value);
}
}
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyTransaction method commit.
@Override
public void commit() throws BimserverLockConflictException, BimserverDatabaseException {
try {
transaction.commit();
transactionAlive = false;
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException(e);
}
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class NewAttributeChange method change.
@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
EClass eClass = eAttribute.getEContainingClass();
KeyValueStore keyValueStore = database.getKeyValueStore();
for (EClass subClass : schema.getSubClasses(eClass)) {
try {
// No data migration if the database is new
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());
PackageMetaData packageMetaData = database.getMetaDataManager().getPackageMetaData(subClass.getEPackage().getName());
int newUnsettedLength = packageMetaData.getUnsettedLength(subClass);
int previousUnsettedLength = packageMetaData.getUnsettedLength(subClass, eAttribute);
byte[] unsetted = new byte[newUnsettedLength];
buffer.get(unsetted, 0, previousUnsettedLength);
int fieldCounter = 0;
for (EStructuralFeature feature : subClass.getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(subClass, feature)) {
if (feature == eAttribute) {
unsetted[fieldCounter / 8] |= (1 << (fieldCounter % 8));
}
fieldCounter++;
}
}
int extra = 0;
ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (newUnsettedLength - previousUnsettedLength) + extra);
newBuffer.put(unsetted);
buffer.position(previousUnsettedLength);
newBuffer.put(buffer);
keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
}
}
} catch (BimserverLockConflictException e) {
LOGGER.error("", e);
}
}
}
Aggregations