Search in sources :

Example 1 with RedisDataType

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);
            }
        }
    }
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) Entry(java.util.Map.Entry) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 2 with RedisDataType

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);
            }
        }
    }
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 3 with RedisDataType

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
            }
        }
    }
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException)

Example 4 with RedisDataType

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();
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) RegionProvider(org.apache.geode.redis.internal.RegionProvider) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) AttributesFactory(org.apache.geode.cache.AttributesFactory) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) HyperLogLogPlus(org.apache.geode.internal.hll.HyperLogLogPlus) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 5 with RedisDataType

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));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) RegionProvider(org.apache.geode.redis.internal.RegionProvider)

Aggregations

RedisDataType (org.apache.geode.redis.internal.RedisDataType)8 ByteArrayWrapper (org.apache.geode.redis.internal.ByteArrayWrapper)5 IOException (java.io.IOException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)2 RegionProvider (org.apache.geode.redis.internal.RegionProvider)2 UnknownHostException (java.net.UnknownHostException)1 Entry (java.util.Map.Entry)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)1 HyperLogLogPlus (org.apache.geode.internal.hll.HyperLogLogPlus)1