Search in sources :

Example 6 with BookieId

use of org.apache.bookkeeper.net.BookieId in project herddb by diennea.

the class PreferLocalBookiePlacementPolicyTest method testEnsamblePolicySingle.

@Test
public void testEnsamblePolicySingle() throws Exception {
    BookieId a = new BookieSocketAddress("a.localhost", 3181).toBookieId();
    Set<BookieId> writableBookies = new HashSet<>();
    writableBookies.add(a);
    registerLocalBookieAddress.invoke(null, a);
    try {
        Set<BookieId> readOnlyBookies = Collections.emptySet();
        PreferLocalBookiePlacementPolicy policy = new PreferLocalBookiePlacementPolicy();
        Set<BookieId> deadBookies = policy.onClusterChanged(writableBookies, readOnlyBookies);
        assertTrue(deadBookies.isEmpty());
        List<BookieId> ensemble = policy.newEnsemble(1, 1, 1, Collections.emptyMap(), Collections.emptySet()).getResult();
        System.out.println(ensemble);
        assertEquals(1, ensemble.size());
        assertEquals(a, ensemble.get(0));
    } finally {
        unregisterLocalBookieAddress.invoke(null, a);
    }
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with BookieId

use of org.apache.bookkeeper.net.BookieId in project herddb by diennea.

the class PreferLocalBookiePlacementPolicy method newEnsemble.

@Override
public PlacementResult<List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, Set<BookieId> excludeBookies) throws BKNotEnoughBookiesException {
    ArrayList<BookieId> newBookies = new ArrayList<>(ensembleSize);
    if (ensembleSize <= 0) {
        return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
    }
    List<BookieId> allBookies;
    synchronized (this) {
        allBookies = new ArrayList<>(knownBookies);
    }
    BookieId localBookie = null;
    for (BookieId bookie : allBookies) {
        if (excludeBookies.contains(bookie)) {
            continue;
        }
        if (LocalBookiesRegistry.isLocalBookie(bookie)) {
            localBookie = bookie;
            break;
        }
    }
    if (localBookie != null) {
        boolean ret = allBookies.remove(localBookie);
        if (!ret) {
            throw new RuntimeException("localBookie not found in list");
        }
        newBookies.add(localBookie);
        --ensembleSize;
        if (ensembleSize == 0) {
            return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
        }
    }
    Collections.shuffle(allBookies);
    for (BookieId bookie : allBookies) {
        if (excludeBookies.contains(bookie)) {
            continue;
        }
        newBookies.add(bookie);
        --ensembleSize;
        if (ensembleSize == 0) {
            return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
        }
    }
    throw new BKException.BKNotEnoughBookiesException();
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) ArrayList(java.util.ArrayList) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)

Aggregations

BookieId (org.apache.bookkeeper.net.BookieId)7 Test (org.junit.Test)5 BookkeeperCommitLog (herddb.cluster.BookkeeperCommitLog)3 ServerConfiguration (herddb.server.ServerConfiguration)3 HashSet (java.util.HashSet)3 DataScanner (herddb.model.DataScanner)2 Table (herddb.model.Table)2 CreateTableStatement (herddb.model.commands.CreateTableStatement)2 InsertStatement (herddb.model.commands.InsertStatement)2 Server (herddb.server.Server)2 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)2 BookkeeperCommitLogManager (herddb.cluster.BookkeeperCommitLogManager)1 ZookeeperMetadataStorageManager (herddb.cluster.ZookeeperMetadataStorageManager)1 TableSpaceManager (herddb.core.TableSpaceManager)1 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)1 Index (herddb.model.Index)1 StatementExecutionException (herddb.model.StatementExecutionException)1 StatementExecutionResult (herddb.model.StatementExecutionResult)1 Transaction (herddb.model.Transaction)1 TransactionContext (herddb.model.TransactionContext)1