use of org.nustaq.reallive.impl.actors.TableSharding 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.TableSharding in project kontraktor by RuedigerMoeller.
the class TableSpaceSharding method createOrLoadTable.
@Override
public IPromise<RealLiveTable> createOrLoadTable(TableDescription desc) {
Promise<RealLiveTable> res = new Promise();
ArrayList<IPromise<RealLiveTable>> results = new ArrayList();
for (int i = 0; i < shards.length; i++) {
TableSpaceActor shard = shards[i];
IPromise<RealLiveTable> table = shard.createOrLoadTable(desc.clone().shardNo(i));
Promise p = new Promise();
results.add(p);
final int finalI = i;
table.then((r, e) -> {
if (e == null)
Log.Info(this, "table creation: " + desc.getName() + " " + finalI);
else if (e instanceof Throwable)
Log.Info(this, (Throwable) e, "failed table creation: " + desc.getName() + " " + finalI);
else
Log.Info(this, "failed table creation: " + desc.getName() + " " + finalI + " " + e);
p.complete(r, e);
});
}
List<IPromise<RealLiveTable>> tables = Actors.all(results).await();
RealLiveTable[] tableShards = new RealLiveTable[tables.size()];
boolean errors = false;
for (int i = 0; i < tables.size(); i++) {
if (tables.get(i).get() == null) {
res.reject(tables.get(i).getError());
errors = true;
break;
} else {
// tables[i].get().shardNo();
int sno = i;
if (tableShards[sno] != null) {
res.reject("shard " + sno + " is present more than once");
errors = true;
break;
}
tableShards[sno] = tables.get(i).get();
}
}
if (!errors) {
TableSharding ts = new TableSharding(func, tableShards, desc);
tableMap.put(desc.getName(), ts);
tableDescriptionMap.put(desc.getName(), desc);
res.resolve(ts);
}
return res;
}
Aggregations