Skip to content

Commit

Permalink
Attempt to integrated Greg Green's PR apache#404 (GEODE-2469)
Browse files Browse the repository at this point in the history
- This work optimizes and simplifies storage of hashes by NOT having a
  separate region for every hash.

Authored-by: Jens Deppe <jdeppe@pivotal.io>
  • Loading branch information
jdeppe-pivotal committed Feb 8, 2020
1 parent 72e8346 commit 9dd3a4c
Show file tree
Hide file tree
Showing 48 changed files with 1,915 additions and 314 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
*/
package org.apache.geode.redis.internal;


/**
* Created by gosullivan on 3/10/17.
*/
public class AutoCloseableLock implements AutoCloseable {
Runnable unlock;

public AutoCloseableLock(Runnable unlockFunction) {
unlock = unlockFunction;
}

@Override
public void close() {
this.unlock.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
*/
package org.apache.geode.redis.internal;

import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
*
* Locking mechanism to support Redis operations
*
*/
public class RedisLockService {


private static final int DEFAULT_TIMEOUT = 1000;
private final int timeoutMS;
private WeakHashMap<Object, Lock> map = new WeakHashMap<Object, Lock>();


/**
* Construct with the default 1000ms timeout setting
*/
public RedisLockService() {
this(DEFAULT_TIMEOUT);
}

/**
* Construct with the timeout setting
*
* @param timeoutMS the default timeout to wait for lock
*/
public RedisLockService(int timeoutMS) {
this.timeoutMS = timeoutMS;
}

/**
* Obtain a lock
*
* @param name the lock name/key
* @return true if lock establish prior to timeout
*/
public synchronized boolean lock(Object name) {
if (name == null)
return false;

Lock lock = map.get(name);

if (lock == null) {
lock = new ReentrantLock();
map.put(name, lock);
}

try {
return lock.tryLock(timeoutMS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
return false;
}
}

/**
* Release the given lock
*
* @param name the lock name
*/
public synchronized void unlock(Object name) {
if (name == null)
return;

Lock lock = map.get(name);

if (lock == null) {
return;
}

try {
lock.unlock();
} finally {
map.remove(name);
}
}

/**
* Retrieve the managed lock
*
* @param name the name key for lock
* @return the manage lock (null if does not exist)
*/
Lock getLock(Object name) {
return map.get(name);
}

}
16 changes: 10 additions & 6 deletions geode-redis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ apply from: "${project.projectDir}/../gradle/publish-java.gradle"

dependencies {
compile(platform(project(':boms:geode-all-bom')))
implementation(project(':geode-serialization'))
implementation(project(':geode-logging'))
compile(project(':geode-core'))
compile(project(':geode-gfsh'))
compile('com.github.davidmoten:geo')
compile('io.netty:netty-all')
compile('org.apache.logging.log4j:log4j-api')
compile(project(':geode-gfsh'))
distributedTestCompile(project(':geode-dunit'))
integrationTestCompile('redis.clients:jedis')
distributedTestCompile('redis.clients:jedis')

implementation(project(':geode-serialization'))
implementation(project(':geode-logging'))

testCompile('org.mockito:mockito-core')
testCompile(project(':geode-junit'))

integrationTestCompile('redis.clients:jedis')
integrationTestCompile(project(':geode-junit'))

distributedTestCompile(project(':geode-dunit'))
distributedTestCompile('redis.clients:jedis')
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.internal.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
Expand All @@ -51,12 +50,10 @@ public class GeoJUnitTest {
private static Jedis jedis;
private static GeodeRedisServer server;
private static GemFireCache cache;
private static Random rand;
private static int port = 6379;

@BeforeClass
public static void setUp() throws IOException {
rand = new Random();
CacheFactory cf = new CacheFactory();
// cf.set("log-file", "redis.log");
cf.set(LOG_LEVEL, "error");
Expand All @@ -70,6 +67,12 @@ public static void setUp() throws IOException {
jedis = new Jedis("localhost", port, 10000000);
}

@After
public void cleanup() {
jedis.zrem("Sicily", "Palermo", "Catania");
}


@Test
public void testGeoAdd() {
Map<String, GeoCoordinate> memberCoordinateMap = new HashMap<>();
Expand Down

0 comments on commit 9dd3a4c

Please sign in to comment.