use of org.apache.geode.redis.internal.ByteArrayWrapper 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.ByteArrayWrapper 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.ByteArrayWrapper in project geode by apache.
the class HLenExecutor 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(), ArityDef.HLEN));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_HASH, context);
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
final int regionSize = keyRegion.size();
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), regionSize));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HMSetExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 3 || commandElems.size() % 2 == 1) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HMSET));
return;
}
ByteArrayWrapper key = command.getKey();
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getOrCreateRegion(context, key, RedisDataType.REDIS_HASH);
Map<ByteArrayWrapper, ByteArrayWrapper> map = new HashMap<ByteArrayWrapper, ByteArrayWrapper>();
for (int i = 2; i < commandElems.size(); i += 2) {
byte[] fieldArray = commandElems.get(i);
ByteArrayWrapper field = new ByteArrayWrapper(fieldArray);
byte[] value = commandElems.get(i + 1);
map.put(field, new ByteArrayWrapper(value));
}
keyRegion.putAll(map);
command.setResponse(Coder.getSimpleStringResponse(context.getByteBufAllocator(), SUCCESS));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HScanExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 3) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HSCAN));
return;
}
ByteArrayWrapper key = command.getKey();
@SuppressWarnings("unchecked") Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = (Region<ByteArrayWrapper, ByteArrayWrapper>) context.getRegionProvider().getRegion(key);
checkDataType(key, RedisDataType.REDIS_HASH, context);
if (keyRegion == null) {
command.setResponse(Coder.getScanResponse(context.getByteBufAllocator(), new ArrayList<String>()));
return;
}
byte[] cAr = commandElems.get(2);
String cursorString = Coder.bytesToString(cAr);
int cursor = 0;
Pattern matchPattern = null;
String globMatchPattern = null;
int count = DEFUALT_COUNT;
try {
cursor = Integer.parseInt(cursorString);
} catch (NumberFormatException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_CURSOR));
return;
}
if (cursor < 0) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_CURSOR));
return;
}
if (commandElems.size() > 4) {
try {
byte[] bytes = commandElems.get(3);
String tmp = Coder.bytesToString(bytes);
if (tmp.equalsIgnoreCase("MATCH")) {
bytes = commandElems.get(4);
globMatchPattern = Coder.bytesToString(bytes);
} else if (tmp.equalsIgnoreCase("COUNT")) {
bytes = commandElems.get(4);
count = Coder.bytesToInt(bytes);
}
} catch (NumberFormatException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_COUNT));
return;
}
}
if (commandElems.size() > 6) {
try {
byte[] bytes = commandElems.get(5);
String tmp = Coder.bytesToString(bytes);
if (tmp.equalsIgnoreCase("MATCH")) {
bytes = commandElems.get(6);
globMatchPattern = Coder.bytesToString(bytes);
} else if (tmp.equalsIgnoreCase("COUNT")) {
bytes = commandElems.get(6);
count = Coder.bytesToInt(bytes);
}
} catch (NumberFormatException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_COUNT));
return;
}
}
if (count < 0) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_COUNT));
return;
}
try {
matchPattern = convertGlobToRegex(globMatchPattern);
} catch (PatternSyntaxException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), RedisConstants.ERROR_ILLEGAL_GLOB));
return;
}
List<Object> returnList = getIteration(new HashSet(keyRegion.entrySet()), matchPattern, count, cursor);
command.setResponse(Coder.getScanResponse(context.getByteBufAllocator(), returnList));
}
Aggregations