use of jetbrains.exodus.env.TransactionalExecutable in project xodus by JetBrains.
the class VfsSettings method get.
ByteIterable get(@Nullable final Transaction txn, @NotNull final String settingName) {
final ArrayByteIterable key = StringBinding.stringToEntry(settingName);
if (txn != null) {
return settingStore.get(txn, key);
}
final ByteIterable[] result = new ByteIterable[1];
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
result[0] = settingStore.get(txn, key);
}
});
return result[0];
}
use of jetbrains.exodus.env.TransactionalExecutable in project xodus by JetBrains.
the class GarbageCollectorTestInMemory method testTextIndexLikeWithDeletionsAndConcurrentReading.
@Test
public void testTextIndexLikeWithDeletionsAndConcurrentReading() throws InterruptedException, BrokenBarrierException {
final long started = System.currentTimeMillis();
prepare();
final Transaction txn = env.beginTransaction();
final Store store = env.openStore("store", getStoreConfig(false), txn);
final Store storeDups = env.openStore("storeDups", getStoreConfig(true), txn);
txn.commit();
final Throwable[] throwable = { null };
final JobProcessor[] processors = new JobProcessor[10];
for (int i = 0; i < processors.length; ++i) {
processors[i] = ThreadJobProcessorPool.getOrCreateJobProcessor("test processor" + i);
processors[i].start();
}
final CyclicBarrier barrier = new CyclicBarrier(processors.length + 1);
processors[0].queue(new Job() {
@Override
protected void execute() throws Throwable {
barrier.await();
try {
while (System.currentTimeMillis() - started < TEST_DURATION) {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
int randomInt = rnd.nextInt() & 0x3fffffff;
final int count = 4 + (randomInt) & 0x1f;
for (int j = 0; j < count; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
final int valueLength = 50 + (randomInt % 100);
store.put(txn, key, new ArrayByteIterable(new byte[valueLength]));
storeDups.put(txn, key, IntegerBinding.intToEntry(randomInt % 32));
}
randomInt = (randomInt * randomInt) & 0x3fffffff;
for (int j = 0; j < count; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
store.delete(txn, key);
try (Cursor cursor = storeDups.openCursor(txn)) {
if (cursor.getSearchBoth(key, IntegerBinding.intToEntry(randomInt % 32))) {
cursor.deleteCurrent();
}
}
}
}
});
Thread.sleep(0);
}
} catch (Throwable t) {
throwable[0] = t;
}
}
});
for (int i = 1; i < processors.length; ++i) {
processors[i].queue(new Job() {
@Override
protected void execute() throws Throwable {
try {
barrier.await();
while (System.currentTimeMillis() - started < TEST_DURATION) {
int randomInt = rnd.nextInt() & 0x3fffffff;
for (int j = 0; j < 100; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
getAutoCommit(store, key);
getAutoCommit(storeDups, key);
Thread.sleep(0);
}
Thread.sleep(50);
}
} catch (Throwable t) {
throwable[0] = t;
}
}
});
}
barrier.await();
for (final JobProcessor processor : processors) {
processor.finish();
}
final Throwable t = throwable[0];
if (t != null) {
memory.dump(new File(System.getProperty("user.home"), "dump"));
logger.error("User code exception: ", t);
Assert.assertTrue(false);
}
}
use of jetbrains.exodus.env.TransactionalExecutable in project xodus by JetBrains.
the class GarbageCollectorTestInMemory method testTextIndexLikeWithDeletions.
private void testTextIndexLikeWithDeletions(boolean useExpirationChecker) {
final long started = System.currentTimeMillis();
prepare(useExpirationChecker);
final Transaction txn = env.beginTransaction();
final Store store = env.openStore("store", getStoreConfig(false), txn);
final Store storeDups = env.openStore("storeDups", getStoreConfig(true), txn);
txn.commit();
try {
while (System.currentTimeMillis() - started < TEST_DURATION) {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
int randomInt = rnd.nextInt() & 0x3fffffff;
final int count = 4 + (randomInt) & 0x1f;
for (int j = 0; j < count; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
final int valueLength = 50 + (randomInt % 100);
store.put(txn, key, new ArrayByteIterable(new byte[valueLength]));
storeDups.put(txn, key, IntegerBinding.intToEntry(randomInt % 32));
}
randomInt = (randomInt * randomInt) & 0x3fffffff;
for (int j = 0; j < count / 2; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
store.delete(txn, key);
try (Cursor cursor = storeDups.openCursor(txn)) {
if (cursor.getSearchBoth(key, IntegerBinding.intToEntry(randomInt % 32))) {
cursor.deleteCurrent();
}
}
}
}
});
Thread.sleep(0);
}
} catch (Throwable t) {
memory.dump(new File(System.getProperty("user.home"), "dump"));
logger.error("User code exception: ", t);
Assert.assertTrue(false);
}
}
use of jetbrains.exodus.env.TransactionalExecutable in project xodus by JetBrains.
the class GarbageCollectorTestInMemory method testTextIndexLike.
private void testTextIndexLike(boolean useExpirationChecker) {
final long started = System.currentTimeMillis();
prepare(useExpirationChecker);
final Transaction txn = env.beginTransaction();
final Store store = env.openStore("store", getStoreConfig(false), txn);
final Store storeDups = env.openStore("storeDups", getStoreConfig(true), txn);
txn.commit();
try {
while (System.currentTimeMillis() - started < TEST_DURATION) {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
int randomInt = rnd.nextInt() & 0x3fffffff;
final int count = 4 + (randomInt) & 0x1f;
for (int j = 0; j < count; randomInt += ++j) {
final int intKey = randomInt & 0x3fff;
final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
final int valueLength = 50 + (randomInt % 100);
store.put(txn, key, new ArrayByteIterable(new byte[valueLength]));
storeDups.put(txn, key, IntegerBinding.intToEntry(randomInt % 32));
}
}
});
Thread.sleep(0);
}
} catch (Throwable t) {
memory.dump(new File(System.getProperty("user.home"), "dump"));
logger.error("User code exception: ", t);
Assert.assertTrue(false);
}
}
Aggregations