Search in sources :

Example 41 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class ZKRegistrationManager method removeCookie.

@Override
public void removeCookie(String bookieId, Version version) throws BookieException {
    String zkPath = getCookiePath(bookieId);
    try {
        zk.delete(zkPath, (int) ((LongVersion) version).getLongVersion());
    } catch (NoNodeException e) {
        throw new CookieNotFoundException(bookieId);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MetadataStoreException("Interrupted deleting cookie for bookie " + bookieId, e);
    } catch (KeeperException e) {
        throw new MetadataStoreException("Failed to delete cookie for bookie " + bookieId);
    }
    log.info("Removed cookie from {} for bookie {}.", cookiePath, bookieId);
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) LongVersion(org.apache.bookkeeper.versioning.LongVersion) CookieNotFoundException(org.apache.bookkeeper.bookie.BookieException.CookieNotFoundException) BKInterruptedException(org.apache.bookkeeper.client.BKException.BKInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Example 42 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class ZKRegistrationClient method getChildren.

private CompletableFuture<Versioned<Set<BookieSocketAddress>>> getChildren(String regPath, Watcher watcher) {
    CompletableFuture<Versioned<Set<BookieSocketAddress>>> future = FutureUtils.createFuture();
    zk.getChildren(regPath, watcher, (rc, path, ctx, children, stat) -> {
        if (Code.OK != rc) {
            ZKException zke = new ZKException();
            zke.fillInStackTrace();
            future.completeExceptionally(zke);
            return;
        }
        Version version = new LongVersion(stat.getCversion());
        Set<BookieSocketAddress> bookies = convertToBookieAddresses(children);
        future.complete(new Versioned<>(bookies, version));
    }, null);
    return future;
}
Also used : ZKException(org.apache.bookkeeper.client.BKException.ZKException) Versioned(org.apache.bookkeeper.versioning.Versioned) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion)

Example 43 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class TestZkRegistrationClient method testGetReadOnlyBookies.

@Test
public void testGetReadOnlyBookies() throws Exception {
    Set<BookieSocketAddress> addresses = prepareNBookies(10);
    List<String> children = Lists.newArrayList();
    for (BookieSocketAddress address : addresses) {
        children.add(address.toString());
    }
    Stat stat = mock(Stat.class);
    when(stat.getCversion()).thenReturn(1234);
    mockGetChildren(regReadonlyPath, false, Code.OK.intValue(), children, stat);
    Versioned<Set<BookieSocketAddress>> result = result(zkRegistrationClient.getReadOnlyBookies());
    assertEquals(new LongVersion(1234), result.getVersion());
    assertSetEquals(addresses, result.getValue());
}
Also used : Stat(org.apache.zookeeper.data.Stat) Set(java.util.Set) HashSet(java.util.HashSet) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testRemoveLedgerMetadataSuccess.

@Test
public void testRemoveLedgerMetadataSuccess() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    LongVersion version = new LongVersion(1234L);
    mockZkDelete(ledgerStr, (int) version.getLongVersion(), KeeperException.Code.OK.intValue());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.removeLedgerMetadata(ledgerId, version, callbackFuture);
    result(callbackFuture);
    verify(mockZk, times(1)).delete(eq(ledgerStr), eq(1234), any(VoidCallback.class), eq(null));
}
Also used : VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testWriteLedgerMetadataBadVersion.

@Test
public void testWriteLedgerMetadataBadVersion() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    metadata.setVersion(new LongVersion(1234L));
    mockZkSetData(ledgerStr, metadata.serialize(), 1234, KeeperException.Code.BADVERSION.intValue(), null);
    assertEquals(new LongVersion(1234L), metadata.getVersion());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.writeLedgerMetadata(ledgerId, metadata, callbackFuture);
    try {
        result(callbackFuture);
        fail("Should fail on writing ledger metadata if encountering bad version");
    } catch (BKException bke) {
        assertEquals(Code.MetadataVersionException, bke.getCode());
    }
    // version remain unchanged
    assertEquals(new LongVersion(1234L), metadata.getVersion());
    verify(mockZk, times(1)).setData(eq(ledgerStr), any(byte[].class), eq(1234), any(StatCallback.class), any());
}
Also used : LongVersion(org.apache.bookkeeper.versioning.LongVersion) BKException(org.apache.bookkeeper.client.BKException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

LongVersion (org.apache.bookkeeper.versioning.LongVersion)56 Test (org.junit.Test)37 Versioned (org.apache.bookkeeper.versioning.Versioned)29 Stat (org.apache.zookeeper.data.Stat)25 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Version (org.apache.bookkeeper.versioning.Version)18 GenericCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture)16 BKException (org.apache.bookkeeper.client.BKException)12 VoidCallback (org.apache.zookeeper.AsyncCallback.VoidCallback)12 Set (java.util.Set)11 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 StatCallback (org.apache.zookeeper.AsyncCallback.StatCallback)10 DataCallback (org.apache.zookeeper.AsyncCallback.DataCallback)9 Before (org.junit.Before)9 URI (java.net.URI)8 ZKException (org.apache.distributedlog.exceptions.ZKException)8 KeeperException (org.apache.zookeeper.KeeperException)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Assert.fail (org.junit.Assert.fail)8