use of org.nustaq.reallive.impl.actors.RealLiveTableActor in project kontraktor by RuedigerMoeller.
the class EmbeddedRealLive method createTable.
/**
* WARNING: never create more than one table using the same file. This will
* result in corrupted data for sure. As actor refs (tables) are thread save,
* just init a singleton containing all your tables once.
*
* @param desc
* @param dataDir - if null use path from description
* @return a thread save actor reference to a newly loaded or created table
*/
public IPromise<RealLiveTable> createTable(TableDescription desc, String dataDir) {
RealLiveTableActor table = Actors.AsActor(RealLiveTableActor.class);
Supplier<RecordStorage> memFactory;
if (desc.getFilePath() == null) {
Log.Info(this, "no file specified. all data in memory " + desc.getName());
switch(desc.getStorageType()) {
case CACHED:
memFactory = () -> new CachedOffHeapStorage(new OffHeapRecordStorage(desc.getKeyLen(), desc.getSizeMB(), desc.getNumEntries()), new HeapRecordStorage());
break;
default:
Log.Error(this, "unknown storage type " + desc.getStorageType() + " default to PERSIST");
case PERSIST:
memFactory = () -> new OffHeapRecordStorage(desc.getKeyLen(), desc.getSizeMB(), desc.getNumEntries());
break;
case TEMP:
memFactory = () -> new HeapRecordStorage();
break;
}
} else {
String bp = dataDir == null ? desc.getFilePath() : dataDir;
desc.filePath(bp);
new File(bp).mkdirs();
String file = bp + "/" + desc.getName() + "_" + desc.getShardNo() + ".bin";
switch(desc.getStorageType()) {
case CACHED:
Log.Info(this, "memory mapping file " + file);
memFactory = () -> new CachedOffHeapStorage(new OffHeapRecordStorage(file, desc.getKeyLen(), desc.getSizeMB(), desc.getNumEntries()), new HeapRecordStorage());
break;
default:
Log.Error(this, "unknown storage type " + desc.getStorageType() + " default to PERSIST");
case PERSIST:
Log.Info(this, "memory mapping file " + file);
memFactory = () -> new OffHeapRecordStorage(file, desc.getKeyLen(), desc.getSizeMB(), desc.getNumEntries());
break;
case TEMP:
memFactory = () -> new HeapRecordStorage();
break;
}
}
table.init(memFactory, desc).await(30_000);
return new Promise(table);
}
use of org.nustaq.reallive.impl.actors.RealLiveTableActor in project kontraktor by RuedigerMoeller.
the class Basic method testActorOutside.
@Test
public void testActorOutside() throws InterruptedException {
RealLiveTableActor rls = Actors.AsActor(RealLiveTableActor.class);
rls.init(() -> new OffHeapRecordStorage(32, 500, 500_000), null);
TA ta = new TA();
ta.runTest(rls).await();
ta.stop();
rls.stop();
}
use of org.nustaq.reallive.impl.actors.RealLiveTableActor in project kontraktor by RuedigerMoeller.
the class Basic method testActorShard.
@Test
public void testActorShard() throws InterruptedException {
RealLiveTableActor[] rls = new RealLiveTableActor[8];
for (int i = 0; i < rls.length; i++) {
rls[i] = Actors.AsActor(RealLiveTableActor.class);
rls[i].init(() -> new OffHeapRecordStorage(32, 500 / rls.length, 700_000 / rls.length), null);
}
ShardFunc sfunc = key -> Math.abs(key.hashCode()) % rls.length;
TableSharding sharding = new TableSharding(sfunc, rls, null);
TA ta = Actors.AsActor(TA.class);
// while( System.currentTimeMillis() != 0)
{
ta.runTest(sharding).await(50009);
}
ta.stop();
sharding.stop();
}
use of org.nustaq.reallive.impl.actors.RealLiveTableActor in project kontraktor by RuedigerMoeller.
the class Basic method testActor.
@Test
public void testActor() throws InterruptedException {
RealLiveTableActor rls = Actors.AsActor(RealLiveTableActor.class, 100_000);
rls.init(() -> new OffHeapRecordStorage(32, 500, 500_000), null);
TA ta = Actors.AsActor(TA.class);
ta.runTest(rls).await(20_000);
ta.stop();
rls.stop();
}
use of org.nustaq.reallive.impl.actors.RealLiveTableActor in project kontraktor by RuedigerMoeller.
the class TableSpaceActor method createOrLoadTable.
@Override
public IPromise<RealLiveTable> createOrLoadTable(TableDescription desc) {
if (tables.containsKey(desc.getName())) {
return resolve(tables.get(desc.getName()));
}
RealLiveTableActor table = createTableActor(desc);
tables.put(desc.getName(), table);
return resolve(table);
}
Aggregations