diff --git a/couchbase/README.md b/couchbase/README.md index 4004cb7f0521d6c760144b85ba1c8ba18346285b..efe16baccaade5b212a886094d267f40d36190ab 100644 --- a/couchbase/README.md +++ b/couchbase/README.md @@ -1,5 +1,5 @@ <!-- -Copyright (c) 2015 YCSB contributors. All rights reserved. +Copyright (c) 2015 - 2016 YCSB contributors. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You @@ -51,6 +51,13 @@ Please see the general instructions in the `doc` folder if you are not sure how bin/ycsb run couchbase -s -P workloads/workloada -p couchbase.useJson=false ``` +## Scans in the CouchbaseClient +The scan operation in the CouchbaseClient requires a Couchbase View to be created manually. To do this: +1. Go to the Couchbase UI, then to Views +2. Create a new development view, specify a ddoc and view name, use these in your YCSB properties. See Configuration Options below. +3. The default map code is sufficient. +4. Save, and publish this View. + ## Configuration Options Since no setup is the same and the goal of YCSB is to deliver realistic benchmarks, here are some setups that you can tune. Note that if you need more flexibility (let's say a custom transcoder), you still need to extend this driver and implement the facilities on your own. @@ -59,9 +66,11 @@ You can set the following properties (with the default settings applied): - couchbase.url=http://127.0.0.1:8091/pools => The connection URL from one server. - couchbase.bucket=default => The bucket name to use. - couchbase.password= => The password of the bucket. - - couchbase.checkFutures=true => If the futures should be inspected (makes ops sync). - couchbase.persistTo=0 => Observe Persistence ("PersistTo" constraint). - couchbase.replicateTo=0 => Observe Replication ("ReplicateTo" constraint). + - couchbase.ddoc => The ddoc name used for scanning + - couchbase.view => The view name used for scanning + - couchbase.stale => How to deal with stale values in View Query for scanning. (OK, FALSE, UPDATE_AFTER) - couchbase.json=true => Use json or java serialization as target format. diff --git a/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java b/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java index d5179b34915ae86f4e18c52a91fce97172938a27..1eb3aeb318d06703e740f10562c64baa7fd6ec86 100644 --- a/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java +++ b/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 Yahoo! Inc. All rights reserved. + * Copyright (c) 2013 - 2016 YCSB contributors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -17,6 +17,7 @@ package com.yahoo.ycsb.db; +import com.couchbase.client.protocol.views.*; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; @@ -73,6 +74,13 @@ public class CouchbaseClient extends DB { public static final String PERSIST_PROPERTY = "couchbase.persistTo"; public static final String REPLICATE_PROPERTY = "couchbase.replicateTo"; public static final String JSON_PROPERTY = "couchbase.json"; + public static final String DESIGN_DOC_PROPERTY = "couchbase.ddoc"; + public static final String VIEW_PROPERTY = "couchbase.view"; + public static final String STALE_PROPERTY = "couchbase.stale"; + public static final String SCAN_PROPERTY = "scanproportion"; + + public static final String STALE_PROPERTY_DEFAULT = Stale.OK.name(); + public static final String SCAN_PROPERTY_DEFAULT = "0.0"; protected static final ObjectMapper JSON_MAPPER = new ObjectMapper(); @@ -81,6 +89,10 @@ public class CouchbaseClient extends DB { private ReplicateTo replicateTo; private boolean checkFutures; private boolean useJson; + private String designDoc; + private String viewName; + private Stale stale; + private View view; private final Logger log = LoggerFactory.getLogger(getClass()); @Override @@ -97,6 +109,12 @@ public class CouchbaseClient extends DB { persistTo = parsePersistTo(props.getProperty(PERSIST_PROPERTY, "0")); replicateTo = parseReplicateTo(props.getProperty(REPLICATE_PROPERTY, "0")); + designDoc = getProperties().getProperty(DESIGN_DOC_PROPERTY); + viewName = getProperties().getProperty(VIEW_PROPERTY); + stale = Stale.valueOf(getProperties().getProperty(STALE_PROPERTY, STALE_PROPERTY_DEFAULT).toUpperCase()); + + Double scanproportion = Double.valueOf(props.getProperty(SCAN_PROPERTY, SCAN_PROPERTY_DEFAULT)); + Properties systemProperties = System.getProperties(); systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger"); System.setProperties(systemProperties); @@ -110,6 +128,15 @@ public class CouchbaseClient extends DB { } catch (Exception e) { throw new DBException("Could not create CouchbaseClient object.", e); } + + if (scanproportion > 0) { + try { + view = client.getView(designDoc, viewName); + } catch (Exception e) { + throw new DBException(String.format("%s=%s and %s=%s provided, unable to connect to view.", + DESIGN_DOC_PROPERTY, designDoc, VIEW_PROPERTY, viewName), e.getCause()); + } + } } /** @@ -194,8 +221,26 @@ public class CouchbaseClient extends DB { * @return Status.ERROR, because not implemented yet. */ @Override - public Status scan(final String table, final String startkey, final int recordcount, - final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) { + public Status scan(final String table, final String startkey, final int recordcount, final Set<String> fields, + final Vector<HashMap<String, ByteIterator>> result) { + try { + Query query = new Query().setRangeStart(startkey) + .setLimit(recordcount) + .setIncludeDocs(true) + .setStale(stale); + ViewResponse response = client.query(view, query); + + for (ViewRow row : response) { + HashMap<String, ByteIterator> rowMap = new HashMap(); + decode(row.getDocument(), fields, rowMap); + result.add(rowMap); + } + + return Status.OK; + } catch (Exception e) { + log.error(e.getMessage()); + } + return Status.ERROR; }