From f886c1e7988f8f4965cb88a1fe2f6bad2c61b56d Mon Sep 17 00:00:00 2001 From: Dan Smith <dsmith@pivotal.io> Date: Tue, 27 Mar 2018 21:28:46 -0700 Subject: [PATCH] [geode] Ensure geode client will work with v1.3 by removing references to internal classes (#1069) * Geode 1.3 changed some of it's internals. The geode binding was using an internal Geode class which means it won't compile against later versions of geode. * Based on review comments, leaving the geode version alone and adding documentation to the README on how to change the version. * Removed incubating from the geode name and website in README, because geode is no longer incubating. --- geode/README.md | 8 ++- .../java/com/yahoo/ycsb/db/GeodeClient.java | 54 ++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/geode/README.md b/geode/README.md index 2b93af8e..8b580812 100644 --- a/geode/README.md +++ b/geode/README.md @@ -17,11 +17,11 @@ LICENSE file. ## Quick Start -This section describes how to run YCSB on Apache Geode (incubating). +This section describes how to run YCSB on Apache Geode. ### Get Apache Geode -You can download Geode from http://geode.incubator.apache.org/releases/ +You can download Geode from https://geode.apache.org/releases/ #### Start Geode Cluster @@ -64,5 +64,9 @@ cluster. To make the ycsb driver a peer member of the distributed system use the property `-p geode.topology=p2p -p geode.locator=host[port]` +YCSB uses geode 1.2.0, which should be compatible with all later +versions of the geode server. To make YCSB run with a different version of the +geode client, you can change the geode.version property in pom.xml. + Note: For update workloads, please use the property `-p writeallfields=true` diff --git a/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java b/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java index aab0c99c..15f89184 100644 --- a/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java +++ b/geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java @@ -17,19 +17,35 @@ package com.yahoo.ycsb.db; -import org.apache.geode.cache.*; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.yahoo.ycsb.ByteArrayByteIterator; +import com.yahoo.ycsb.ByteIterator; +import com.yahoo.ycsb.DB; +import com.yahoo.ycsb.DBException; +import com.yahoo.ycsb.Status; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionExistsException; +import org.apache.geode.cache.RegionFactory; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientCacheFactory; import org.apache.geode.cache.client.ClientRegionFactory; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.apache.geode.internal.admin.remote.DistributionLocatorId; -import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.pdx.JSONFormatter; import org.apache.geode.pdx.PdxInstance; import org.apache.geode.pdx.PdxInstanceFactory; -import com.yahoo.ycsb.*; - -import java.util.*; /** * Apache Geode (incubating) client for the YCSB benchmark.<br /> @@ -84,6 +100,11 @@ public class GeodeClient extends DB { */ private static final String TOPOLOGY_P2P_VALUE = "p2p"; + /** + * Pattern to split up a locator string in the form host[port]. + */ + private static final Pattern LOCATOR_PATTERN = Pattern.compile("(.+)\\[(\\d+)\\]");; + private GemFireCache cache; /** @@ -120,20 +141,26 @@ public class GeodeClient extends DB { } } isClient = true; - DistributionLocatorId locator = null; - if (locatorStr != null) { - locator = new DistributionLocatorId(locatorStr); - } + ClientCacheFactory ccf = new ClientCacheFactory(); ccf.setPdxReadSerialized(true); if (serverPort != 0) { ccf.addPoolServer(serverHost, serverPort); - } else if (locator != null) { - ccf.addPoolLocator(locator.getHost().getCanonicalHostName(), locator.getPort()); + } else { + InetSocketAddress locatorAddress = getLocatorAddress(locatorStr); + ccf.addPoolLocator(locatorAddress.getHostName(), locatorAddress.getPort()); } cache = ccf.create(); } + static InetSocketAddress getLocatorAddress(String locatorStr) { + Matcher matcher = LOCATOR_PATTERN.matcher(locatorStr); + if(!matcher.matches()) { + throw new IllegalStateException("Unable to parse locator: " + locatorStr); + } + return new InetSocketAddress(matcher.group(1), Integer.parseInt(matcher.group(2))); + } + @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { @@ -180,8 +207,7 @@ public class GeodeClient extends DB { } private PdxInstance convertToBytearrayMap(Map<String, ByteIterator> values) { - GemFireCacheImpl gci = (GemFireCacheImpl) CacheFactory.getAnyInstance(); - PdxInstanceFactory pdxInstanceFactory = gci.createPdxInstanceFactory(JSONFormatter.JSON_CLASSNAME); + PdxInstanceFactory pdxInstanceFactory = cache.createPdxInstanceFactory(JSONFormatter.JSON_CLASSNAME); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { pdxInstanceFactory.writeByteArray(entry.getKey(), entry.getValue().toArray()); -- GitLab