use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.
the class TransactionalMapProxySupport method lockAndGet.
private VersionedValue lockAndGet(Data key, long timeout, boolean shouldLoad) {
VersionedValue versionedValue = valueMap.get(key);
if (versionedValue != null) {
return versionedValue;
}
boolean blockReads = tx.getTransactionType() == TransactionType.ONE_PHASE;
MapOperation operation = operationProvider.createTxnLockAndGetOperation(name, key, timeout, timeout, tx.getOwnerUuid(), shouldLoad, blockReads);
operation.setThreadId(ThreadUtil.getThreadId());
try {
int partitionId = partitionService.getPartitionId(key);
Future<VersionedValue> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
versionedValue = future.get();
if (versionedValue == null) {
throw new TransactionTimedOutException("Transaction couldn't obtain lock for the key: " + toObjectIfNeeded(key));
}
valueMap.put(key, versionedValue);
return versionedValue;
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.
the class TransactionalMapProxySupport method putIfAbsentInternal.
Data putIfAbsentInternal(Data key, Data value, NearCachingHook hook) {
boolean unlockImmediately = !valueMap.containsKey(key);
VersionedValue versionedValue = lockAndGet(key, tx.getTimeoutMillis());
if (versionedValue.value != null) {
if (unlockImmediately) {
unlock(key, versionedValue);
return versionedValue.value;
}
addUnlockTransactionRecord(key, versionedValue.version);
return versionedValue.value;
}
MapOperation operation = operationProvider.createTxnSetOperation(name, key, value, versionedValue.version, UNSET);
tx.add(new MapTransactionLogRecord(name, key, getPartitionId(key), operation, tx.getOwnerUuid(), tx.getTxnId(), hook));
return versionedValue.value;
}
use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.
the class TransactionalMapProxySupport method getInternal.
Object getInternal(Object nearCacheKey, Data keyData, boolean skipNearCacheLookup) {
if (!skipNearCacheLookup && nearCacheEnabled) {
Object value = getCachedValue(nearCacheKey, true);
if (value != NOT_CACHED) {
return value;
}
}
MapOperation operation = operationProvider.createGetOperation(name, keyData);
operation.setThreadId(ThreadUtil.getThreadId());
int partitionId = partitionService.getPartitionId(keyData);
try {
Future future = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).invoke();
return future.get();
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.
the class MapKeyLoader method sendBatch.
/**
* Sends the key batches to the partition owners for value
* loading. The returned futures represent pending offloading
* of the value loading on the partition owner. This means
* that once the partition owner receives the keys, it will
* offload the value loading task and return immediately,
* thus completing the future. The future does not mean
* the value loading tasks have been completed or that the
* entries have been loaded and put into the record store.
*
* @param batch a map from partition ID
* to a batch of keys for that partition
* @param replaceExistingValues if the existing
* entries for the loaded keys should be replaced
* @param nodeWideLoadedKeyLimiter controls number of loaded keys
* @return a list of futures representing pending
* completion of the value offloading task
*/
private List<Future> sendBatch(Map<Integer, List<Data>> batch, boolean replaceExistingValues, Semaphore nodeWideLoadedKeyLimiter) {
Set<Entry<Integer, List<Data>>> entries = batch.entrySet();
List<Future> futures = new ArrayList<>(entries.size());
Iterator<Entry<Integer, List<Data>>> iterator = entries.iterator();
while (iterator.hasNext()) {
Entry<Integer, List<Data>> e = iterator.next();
int partitionId = e.getKey();
List<Data> keys = e.getValue();
int numberOfLoadedKeys = keys.size();
try {
MapOperation op = operationProvider.createLoadAllOperation(mapName, keys, replaceExistingValues);
InternalCompletableFuture<Object> future = opService.invokeOnPartition(SERVICE_NAME, op, partitionId);
futures.add(future);
} finally {
nodeWideLoadedKeyLimiter.release(numberOfLoadedKeys);
}
iterator.remove();
}
return futures;
}
use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.
the class MapProxySupport method putInternal.
protected Data putInternal(Object key, Data valueData, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
Data keyData = toDataWithStrategy(key);
MapOperation operation = newPutOperation(keyData, valueData, ttl, ttlUnit, maxIdle, maxIdleUnit);
return (Data) invokeOperation(keyData, operation);
}
Aggregations