Search in sources :

Example 51 with Versioned

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

the class ListBookiesCommandTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    writableBookies = createBookies(3181, 10);
    readonlyBookies = createBookies(4181, 10);
    when(regClient.getWritableBookies()).thenReturn(value(new Versioned<>(writableBookies, new LongVersion(0L))));
    when(regClient.getReadOnlyBookies()).thenReturn(value(new Versioned<>(readonlyBookies, new LongVersion(0L))));
    PowerMockito.mockStatic(CommandHelpers.class, CALLS_REAL_METHODS);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Before(org.junit.Before)

Example 52 with Versioned

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

the class BKLogHandler method getLastLogRecordAsync.

public CompletableFuture<LogRecordWithDLSN> getLastLogRecordAsync(final boolean recover, final boolean includeEndOfStream) {
    final CompletableFuture<LogRecordWithDLSN> promise = new CompletableFuture<LogRecordWithDLSN>();
    streamMetadataStore.logExists(logMetadata.getUri(), logMetadata.getLogName()).whenComplete(new FutureEventListener<Void>() {

        @Override
        public void onSuccess(Void value) {
            readLogSegmentsFromStore(LogSegmentMetadata.DESC_COMPARATOR, LogSegmentFilter.DEFAULT_FILTER, null).whenComplete(new FutureEventListener<Versioned<List<LogSegmentMetadata>>>() {

                @Override
                public void onSuccess(Versioned<List<LogSegmentMetadata>> ledgerList) {
                    if (ledgerList.getValue().isEmpty()) {
                        promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
                        return;
                    }
                    asyncGetLastLogRecord(ledgerList.getValue().iterator(), promise, recover, false, includeEndOfStream);
                }

                @Override
                public void onFailure(Throwable cause) {
                    promise.completeExceptionally(cause);
                }
            });
        }

        @Override
        public void onFailure(Throwable cause) {
            promise.completeExceptionally(cause);
        }
    });
    return promise;
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) CompletableFuture(java.util.concurrent.CompletableFuture) Versioned(org.apache.bookkeeper.versioning.Versioned) FutureEventListener(org.apache.bookkeeper.common.concurrent.FutureEventListener) List(java.util.List)

Example 53 with Versioned

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

the class BKLogHandler method asyncGetFirstLogRecord.

public CompletableFuture<LogRecordWithDLSN> asyncGetFirstLogRecord() {
    final CompletableFuture<LogRecordWithDLSN> promise = new CompletableFuture<LogRecordWithDLSN>();
    streamMetadataStore.logExists(logMetadata.getUri(), logMetadata.getLogName()).whenComplete(new FutureEventListener<Void>() {

        @Override
        public void onSuccess(Void value) {
            readLogSegmentsFromStore(LogSegmentMetadata.COMPARATOR, LogSegmentFilter.DEFAULT_FILTER, null).whenComplete(new FutureEventListener<Versioned<List<LogSegmentMetadata>>>() {

                @Override
                public void onSuccess(Versioned<List<LogSegmentMetadata>> ledgerList) {
                    if (ledgerList.getValue().isEmpty()) {
                        promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
                        return;
                    }
                    CompletableFuture<LogRecordWithDLSN> firstRecord = null;
                    for (LogSegmentMetadata ledger : ledgerList.getValue()) {
                        if (!ledger.isTruncated() && (ledger.getRecordCount() > 0 || ledger.isInProgress())) {
                            firstRecord = asyncReadFirstUserRecord(ledger, DLSN.InitialDLSN);
                            break;
                        }
                    }
                    if (null != firstRecord) {
                        FutureUtils.proxyTo(firstRecord, promise);
                    } else {
                        promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
                    }
                }

                @Override
                public void onFailure(Throwable cause) {
                    promise.completeExceptionally(cause);
                }
            });
        }

        @Override
        public void onFailure(Throwable cause) {
            promise.completeExceptionally(cause);
        }
    });
    return promise;
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) CompletableFuture(java.util.concurrent.CompletableFuture) Versioned(org.apache.bookkeeper.versioning.Versioned) FutureEventListener(org.apache.bookkeeper.common.concurrent.FutureEventListener) List(java.util.List)

Example 54 with Versioned

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

the class LedgerAllocatorPool method initializeAllocators.

/**
 * Initialize simple allocators with given list of allocator names <i>allocators</i>.
 * It initializes a simple allocator with its simple allocator path.
 */
private void initializeAllocators(List<String> allocators) throws IOException, InterruptedException {
    final AtomicInteger numPendings = new AtomicInteger(allocators.size());
    final AtomicInteger numFailures = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(numPendings.get() > 0 ? 1 : 0);
    AsyncCallback.DataCallback dataCallback = new AsyncCallback.DataCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
            if (KeeperException.Code.OK.intValue() != rc) {
                numFailures.incrementAndGet();
                latch.countDown();
                return;
            }
            Versioned<byte[]> allocatorData = new Versioned<byte[]>(data, new LongVersion(stat.getVersion()));
            SimpleLedgerAllocator allocator = new SimpleLedgerAllocator(path, allocatorData, quorumConfigProvider, zkc, bkc);
            allocator.start();
            pendingList.add(allocator);
            if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) {
                latch.countDown();
            }
        }
    };
    for (String name : allocators) {
        String path = poolPath + "/" + name;
        zkc.get().getData(path, false, dataCallback, null);
    }
    latch.await();
    if (numFailures.get() > 0) {
        throw new IOException("Failed to initialize allocators : " + allocators);
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) AsyncCallback(org.apache.zookeeper.AsyncCallback) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Stat(org.apache.zookeeper.data.Stat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongVersion(org.apache.bookkeeper.versioning.LongVersion)

Example 55 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingReadLockPath.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingReadLockPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(new byte[0], new ZkVersion(1)), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Aggregations

Versioned (org.apache.bookkeeper.versioning.Versioned)65 Test (org.junit.Test)45 LongVersion (org.apache.bookkeeper.versioning.LongVersion)32 Stat (org.apache.zookeeper.data.Stat)25 ZkVersion (org.apache.bookkeeper.meta.ZkVersion)21 URI (java.net.URI)19 CompletableFuture (java.util.concurrent.CompletableFuture)14 Version (org.apache.bookkeeper.versioning.Version)14 List (java.util.List)12 ZKException (org.apache.distributedlog.exceptions.ZKException)9 Promise (com.twitter.util.Promise)8 ZKException (com.twitter.distributedlog.exceptions.ZKException)7 LogMetadataForWriter (org.apache.distributedlog.metadata.LogMetadataForWriter)7 Transaction (org.apache.distributedlog.util.Transaction)7 AsyncCallback (org.apache.zookeeper.AsyncCallback)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Transaction (com.twitter.distributedlog.util.Transaction)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 KeeperException (org.apache.zookeeper.KeeperException)6 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)5