Search in sources :

Example 1 with TableSharding

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();
}
Also used : IntStream(java.util.stream.IntStream) org.nustaq.reallive.api(org.nustaq.reallive.api) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Iterator(java.util.Iterator) Test(org.junit.Test) Promise(org.nustaq.kontraktor.Promise) PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch) TableSharding(org.nustaq.reallive.impl.actors.TableSharding) org.nustaq.reallive.impl.storage(org.nustaq.reallive.impl.storage) MapRecord(org.nustaq.reallive.records.MapRecord) IPromise(org.nustaq.kontraktor.IPromise) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.nustaq.reallive.impl(org.nustaq.reallive.impl) Map(java.util.Map) Actor(org.nustaq.kontraktor.Actor) Actors(org.nustaq.kontraktor.Actors) ShardFunc(org.nustaq.reallive.impl.actors.ShardFunc) RealLiveTableActor(org.nustaq.reallive.impl.actors.RealLiveTableActor) ShardFunc(org.nustaq.reallive.impl.actors.ShardFunc) TableSharding(org.nustaq.reallive.impl.actors.TableSharding) RealLiveTableActor(org.nustaq.reallive.impl.actors.RealLiveTableActor) Test(org.junit.Test)

Example 2 with TableSharding

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;
}
Also used : RealLiveTable(org.nustaq.reallive.api.RealLiveTable) ArrayList(java.util.ArrayList) TableSharding(org.nustaq.reallive.impl.actors.TableSharding) Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) IPromise(org.nustaq.kontraktor.IPromise)

Aggregations

IPromise (org.nustaq.kontraktor.IPromise)2 Promise (org.nustaq.kontraktor.Promise)2 TableSharding (org.nustaq.reallive.impl.actors.TableSharding)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IntStream (java.util.stream.IntStream)1 Test (org.junit.Test)1 Actor (org.nustaq.kontraktor.Actor)1 Actors (org.nustaq.kontraktor.Actors)1 PromiseLatch (org.nustaq.kontraktor.util.PromiseLatch)1 org.nustaq.reallive.api (org.nustaq.reallive.api)1 RealLiveTable (org.nustaq.reallive.api.RealLiveTable)1 org.nustaq.reallive.impl (org.nustaq.reallive.impl)1 RealLiveTableActor (org.nustaq.reallive.impl.actors.RealLiveTableActor)1 ShardFunc (org.nustaq.reallive.impl.actors.ShardFunc)1 org.nustaq.reallive.impl.storage (org.nustaq.reallive.impl.storage)1 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)1 MapRecord (org.nustaq.reallive.records.MapRecord)1