Package com.netflix.astyanax.retry

Examples of com.netflix.astyanax.retry.RetryPolicy


        for (int i = 1; i < tokens.length; i++) {
            args[i - 1] = Integer.valueOf(tokens[i]);
        }

        try {
            RetryPolicy rp = instantiate(policyClassName, args, serializedRetryPolicy);
            log.debug("Instantiated RetryPolicy object {} from config string \"{}\"", rp, serializedRetryPolicy);
            return rp;
        } catch (Exception e) {
            throw new PermanentStorageException("Failed to instantiate Astyanax Retry Policy class", e);
        }
View Full Code Here


    this.keyspace = ksContext.getKeyspace();
    this.cf = (cfContext != null) ? cfContext.getColumnFamily() : null;
    this.tracerFactory = ksContext.getTracerFactory();
   
    // process the override retry policy first
    RetryPolicy retryPolicy = ksContext.getConfig().getRetryPolicy();
    retry = (retryPolicy != null) ? retryPolicy : getRetryPolicy(cfContext.getRetryPolicy());
   
    clLevel = resolveConsistencyLevel(ksContext, cfContext);
  }
View Full Code Here

       
        cp.setHosts(ring1);
       
        BigInteger threeNodeRingIncrement = TokenGenerator.MAXIMUM.divide(new BigInteger("3"));

        RetryPolicy retryPolicy = new RunOnce();

        BigInteger key = BigInteger.ZERO;
        LOG.info(key.toString() + " 127.0.1.2");
        OperationResult<String> result = cp.executeWithFailover(new TokenTestOperation(key), retryPolicy);
        assertNotNull(result);
View Full Code Here

        LOG.info(BigIntegerSerializer.get().fromByteBuffer(firstHostOp.getRowKey()).toString());
        LOG.info(BigIntegerSerializer.get().fromByteBuffer(secondHostOp.getRowKey()).toString());
        LOG.info(BigIntegerSerializer.get().fromByteBuffer(thirdHostOp.getRowKey()).toString());
        LOG.info(BigIntegerSerializer.get().fromByteBuffer(maxTokenHostOp.getRowKey()).toString());
        RetryPolicy retryPolicy = new RunOnce();

        OperationResult<String> result = cp.executeWithFailover(firstHostOp, retryPolicy);
        assertNotNull(result);
        assertEquals("127.0.1.2",result.getHost().getIpAddress());
View Full Code Here

        cp.setHosts(ring1);
        LOG.info("testTokenToHostMappingInWrappedRange\n" + TestTokenRange.getRingDetails(ring1));

        Operation<TestClient, String> op = new TokenTestOperation(BigInteger.ZERO);

        RetryPolicy retryPolicy = new RunOnce();

        OperationResult<String> result = cp.executeWithFailover(op, retryPolicy);
        assertNotNull(result);

        // since token ownership wraps node2 should own token 0
View Full Code Here

        cp.setHosts(ring1);
        LOG.info("testTokenToHostMappingOutsideOfRing\n" + TestTokenRange.getRingDetails(ring1));

        Operation<TestClient, String> op = new TokenTestOperation(new BigInteger("1250"));

        RetryPolicy retryPolicy = new RunOnce();

        OperationResult<String> result = cp.executeWithFailover(op, retryPolicy);
        assertNotNull(result);

        // requests for tokens outside the ring will be serviced by host associated with
View Full Code Here

    @Test
    public void testRetryEmptyPool() {
        ConnectionPool<TestClient> pool = createPool();

        RetryPolicy retry = new RunOnce();
        try {
            pool.executeWithFailover(dummyOperation, retry);
            Assert.fail();
        } catch (ConnectionException e) {
            Assert.assertEquals(1, retry.getAttemptCount());
            LOG.error(e);
        }

        retry = new ConstantBackoff(1, 10);
        try {
            pool.executeWithFailover(dummyOperation, retry);
            Assert.fail();
        } catch (ConnectionException e) {
            Assert.assertEquals(10, retry.getAttemptCount());
            LOG.info(e);
        }
    }
View Full Code Here

    @Override
    public void acquire() throws Exception {
       
        Preconditions.checkArgument(ttl == null || TimeUnit.SECONDS.convert(timeout, timeoutUnits) < ttl, "Timeout " + timeout + " must be less than TTL " + ttl);
       
        RetryPolicy retry = backoffPolicy.duplicate();
        retryCount = 0;
        while (true) {
            try {
                long curTimeMicros = getCurrentTimeMicros();
               
                MutationBatch m = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);
                fillLockMutation(m, curTimeMicros, ttl);
                m.execute();
               
                verifyLock(curTimeMicros);
                acquireTime = System.nanoTime();
                return;
            }
            catch (BusyLockException e) {
                release();
                if(!retry.allowRetry())
                    throw e;
                retryCount++;
            }
        }
    }
View Full Code Here

    @Override
    public void acquire() throws Exception {
       
        Preconditions.checkArgument(ttl == null || TimeUnit.SECONDS.convert(timeout, timeoutUnits) < ttl, "Timeout " + timeout + " must be less than TTL " + ttl);
       
        RetryPolicy retry = backoffPolicy.duplicate();
        retryCount = 0;
        while (true) {
            try {
                long curTimeMicros = getCurrentTimeMicros();
               
                MutationBatch m = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);
                fillLockMutation(m, curTimeMicros, ttl);
                m.execute();
               
                verifyLock(curTimeMicros);
                acquireTime = System.currentTimeMillis();
                return;
            }
            catch (BusyLockException e) {
                release();
                if(!retry.allowRetry())
                    throw e;
                retryCount++;
            }
        }
    }
View Full Code Here

            // Try to get the file metadata first. The entire file must be
            // available before it can be downloaded.
            // If not available then we back off and retry using the provided
            // retry policy.
            ObjectMetadata attributes;
            RetryPolicy retry = retryPolicy.duplicate();
            do {
                try {
                    attributes = provider.readMetadata(objectName);
                    if (attributes.isValidForRead())
                        break;
                    if (!retry.allowRetry())
                        throw new NotFoundException("File doesn't exists or isn't ready to be read: " + objectName);
                }
                catch (Exception e) {
                    LOG.warn(e.getMessage());
                    if (!retry.allowRetry())
                        throw e;
                }
            } while (true);

            final AtomicReference<Exception> exception = new AtomicReference<Exception>();
            final AtomicLong totalBytesRead = new AtomicLong();
            final AtomicLong totalBytesRead2 = new AtomicLong();

            // Iterate sequentially building up the batches. Once a complete
            // batch of ids is ready
            // randomize fetching the chunks and then download them in parallel
            List<Integer> idsToRead = Lists.newArrayList();
            for (int block = 0; block < attributes.getChunkCount(); block++) {
                idsToRead.add(block);

                // Got a batch, or reached the end
                if (idsToRead.size() == batchSize || block == attributes.getChunkCount() - 1) {

                    // Read blocks in random order
                    final int firstBlockId = idsToRead.get(0);
                    Collections.shuffle(idsToRead);
                    final AtomicReferenceArray<ByteBuffer> chunks = new AtomicReferenceArray<ByteBuffer>(
                            idsToRead.size());
                    ExecutorService executor = Executors.newFixedThreadPool(
                            concurrencyLevel,
                            new ThreadFactoryBuilder().setDaemon(true)
                                    .setNameFormat("ChunkReader-" + objectName + "-%d").build());
                    try {
                        for (final int chunkId : idsToRead) {
                            executor.submit(new Runnable() {
                                @Override
                                public void run() {
                                    // Do the fetch
                                    RetryPolicy retry = retryPolicy.duplicate();
                                    while (exception.get() == null) {
                                        try {
                                            ByteBuffer chunk = provider.readChunk(objectName, chunkId);
                                            totalBytesRead.addAndGet(chunk.remaining());
                                            chunks.set(chunkId - firstBlockId, chunk);
                                            callback.onChunk(chunkId, chunk);
                                            break;
                                        }
                                        catch (Exception e) {
                                            callback.onChunkException(chunkId, e);
                                            if (retry.allowRetry())
                                                continue;
                                            exception.compareAndSet(null, e);
                                        }
                                    }
                                }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.retry.RetryPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.