protected void writeFailure(AerospikeException ae) { if (ae.getResultCode() == ResultCode.TIMEOUT) { counters.write.timeouts.getAndIncrement(); } else { counters.write.errors.getAndIncrement(); if (args.debug) { ae.printStackTrace(); } } }
protected void readFailure(AerospikeException ae) { if (ae.getResultCode() == ResultCode.TIMEOUT) { counters.read.timeouts.getAndIncrement(); } else { counters.read.errors.getAndIncrement(); if (args.debug) { ae.printStackTrace(); } } }
protected void writeFailure(AerospikeException ae) { if (ae.getResultCode() == ResultCode.TIMEOUT) { counters.write.timeouts.getAndIncrement(); } else { counters.write.errors.getAndIncrement(); if (args.debug) { ae.printStackTrace(); } } }
/** * Size of list, i.e. a number of elements in the list * * @return Number of elements in the list */ public int size() { try { return isEmpty ? 0 : inner.size(); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return 0; } throw ae; } }
/** * Is list empty? * * @return True if list is empty */ public boolean isEmpty() { try { return isEmpty || inner.size() == 0; } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return true; } throw ae; } }
protected void addTransactionally(List<Value> values) { int retries = 10; // retry loop in case of clashing indexes while (retries > 0) { try { inner.update(values); isEmpty = false; return; } catch (AerospikeException ae) { if (ae.getResultCode() == 1402) { retries--; } else { throw ae; } } } }
/** * Returns a map of all keys, values. * * @return A map of all keys, values. */ @SuppressWarnings("unchecked") public Map<K, V> getAll() { List found = null; try { found = inner.scan(); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return new HashMap<>(0); } throw ae; } return toTypedResults(found); }
/** * Returns a count of key, values from the last position. * * @param count maximum number of values to return * @return A map of key, values from the last key value */ @SuppressWarnings("unchecked") public Map<K, V> findLast(int count) { List found = null; try { found = inner.findLast(count); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return new HashMap<>(0); } throw ae; } return toTypedResults(found); }
/** * Does value exist? * * @param index index of the value to check existance for * @return True if value at given index exists */ public boolean exists(int index) throws AerospikeException { try { return index >= 0 && inner.exists(Value.get(index)); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return false; } throw ae; } }
/** * Returns a count of key, values from the last position. * * @param count maximum number of values to return * @return A map of key, values from the last key value */ @SuppressWarnings("unchecked") public Map<K, V> findFirst(int count) { List found = null; try { found = inner.findFirst(count); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { return new HashMap<>(0); } throw ae; } return toTypedResults(found); }
/** * Returns true if this map contains a mapping for the specified key. * * @param key key whose presence in this map is to be tested * @return if this map contains a mapping for the specified key */ public boolean containsKey(K key) { try { return inner.exists(Value.get(key)); } catch (AerospikeException ae) { if (ae.getResultCode() == 1417) { isEmpty = true; } } return false; }
/** * Internal update method that can run sync or async, depending on the provided listener being provided or null. * * @param writeListener * @return */ private K now(WriteListener writeListener) { try { return nowInternal(writeListener); // invoke internal sync version } catch (AerospikeException e) { if (e.getResultCode() == 2) { recordsCache.remove(key); return nowInternal(writeListener); } throw e; } }
/** * Internal update method that can run sync or async, depending on the provided listener being provided or null. * * @param writeListener * @return */ public Key now(WriteListener writeListener) { try { return nowInternal(writeListener); } catch (AerospikeException e) { if (e.getResultCode() == 2) { recordsCache.remove(collectKey(object, defaultNamespace)); return nowInternal(writeListener); } throw e; } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.STRING); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void createIndex( AerospikeClient client, Parameters params, String indexName, String binName ) throws Exception { console.info("Create mapkeys index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName); Policy policy = new Policy(); policy.socketTimeout = 0; // Do not timeout on index create. try { IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.STRING, IndexCollectionType.MAPKEYS); task.waitTillComplete(); } catch (AerospikeException ae) { if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) { throw ae; } } }
private void doPersistWithCas(Object document, AerospikePersistentEntity<?> entity) { try { AerospikeWriteData data = AerospikeWriteData.forWrite(); converter.write(document, data); Key key = data.getKey(); Bin[] bins = data.getBinsAsArray(); ConvertingPropertyAccessor accessor = getPropertyAccessor(entity, document); WritePolicy policy = getCasAwareWritePolicy(data, entity, accessor); Operation[] operations = OperationUtils.operations(bins, Operation::put, Operation.getHeader()); Record newRecord = client.operate(policy, key, operations); accessor.setProperty(entity.getVersionProperty(), newRecord.generation); } catch (AerospikeException e) { int code = e.getResultCode(); if (code == ResultCode.KEY_EXISTS_ERROR || code == ResultCode.GENERATION_ERROR) { throw new OptimisticLockingFailureException("Save document with version value failed", e); } DataAccessException translatedException = exceptionTranslator.translateExceptionIfPossible(e); throw translatedException == null ? e : translatedException; } }