use of org.apache.geode.redis.internal.RedisDataType in project geode by apache.
the class GeodeRedisServer method checkForRegions.
private void checkForRegions() {
Collection<Entry<String, RedisDataType>> entrySet = this.regionCache.metaEntrySet();
for (Entry<String, RedisDataType> entry : entrySet) {
String regionName = entry.getKey();
RedisDataType type = entry.getValue();
Region<?, ?> newRegion = cache.getRegion(regionName);
if (newRegion == null && type != RedisDataType.REDIS_STRING && type != RedisDataType.REDIS_HLL && type != RedisDataType.REDIS_PROTECTED) {
try {
this.regionCache.createRemoteRegionReferenceLocally(Coder.stringToByteArrayWrapper(regionName), type);
} catch (Exception e) {
if (logger.errorEnabled())
logger.error(e);
}
}
}
}
use of org.apache.geode.redis.internal.RedisDataType in project geode by apache.
the class GeodeRedisServer method afterKeyDestroy.
/**
* When a key is removed then this function will make sure the associated queries with the key are
* also removed from each vm to avoid unnecessary data retention
*/
private void afterKeyDestroy(EntryEvent<String, RedisDataType> event) {
if (event.isOriginRemote()) {
final String key = (String) event.getKey();
final RedisDataType value = event.getOldValue();
if (value != null && value != RedisDataType.REDIS_STRING && value != RedisDataType.REDIS_HLL && value != RedisDataType.REDIS_PROTECTED) {
ByteArrayWrapper kW = Coder.stringToByteArrayWrapper(key);
Region<?, ?> r = this.regionCache.getRegion(kW);
if (r != null) {
this.regionCache.removeRegionReferenceLocally(kW, value);
}
}
}
}
use of org.apache.geode.redis.internal.RedisDataType in project geode by apache.
the class GeodeRedisServer method afterKeyCreate.
/**
* Takes an entry event and processes it. If the entry denotes that a
* {@link RedisDataType#REDIS_LIST} or {@link RedisDataType#REDIS_SORTEDSET} was created then this
* function will call the necessary calls to create the parameterized queries for those keys.
*
* @param event EntryEvent from meta data region
*/
private void afterKeyCreate(EntryEvent<String, RedisDataType> event) {
if (event.isOriginRemote()) {
final String key = (String) event.getKey();
final RedisDataType value = event.getNewValue();
if (value != RedisDataType.REDIS_STRING && value != RedisDataType.REDIS_HLL && value != RedisDataType.REDIS_PROTECTED) {
try {
this.regionCache.createRemoteRegionReferenceLocally(Coder.stringToByteArrayWrapper(key), value);
} catch (RegionDestroyedException ignore) {
// Region already destroyed, ignore
}
}
}
}
use of org.apache.geode.redis.internal.RedisDataType in project geode by apache.
the class GeodeRedisServer method initializeRedis.
private void initializeRedis() {
synchronized (this.cache) {
Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
Region<String, RedisDataType> redisMetaData;
InternalCache gemFireCache = (InternalCache) cache;
try {
if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
stringsRegion = regionFactory.create(STRING_REGION);
}
if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
hLLRegion = regionFactory.create(HLL_REGION);
}
if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
AttributesFactory af = new AttributesFactory();
af.addCacheListener(metaListener);
af.setDataPolicy(DataPolicy.REPLICATE);
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(), ira);
}
} catch (IOException | ClassNotFoundException e) {
// only if loading snapshot, not here
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
this.regionCache = new RegionProvider(stringsRegion, hLLRegion, redisMetaData, expirationFutures, expirationExecutor, this.DEFAULT_REGION_TYPE);
redisMetaData.put(REDIS_META_DATA_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(HLL_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(STRING_REGION, RedisDataType.REDIS_PROTECTED);
}
checkForRegions();
}
use of org.apache.geode.redis.internal.RedisDataType in project geode by apache.
the class TTLExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), getArgsError()));
return;
}
ByteArrayWrapper key = command.getKey();
RegionProvider rC = context.getRegionProvider();
boolean exists = false;
RedisDataType val = rC.getRedisDataType(key);
if (val != null)
exists = true;
if (!exists) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
long ttl = rC.getExpirationDelayMillis(key);
if (ttl == 0L) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NO_TIMEOUT));
return;
}
if (!timeUnitMillis())
ttl = ttl / millisInSecond;
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), ttl));
}
Aggregations