From dc5c52264607691021c9bc70aed8955d05d7af9d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 9 Aug 2019 14:50:24 +0000 Subject: Remove legacy orderdoc, groupdoc, userdoc documentids --- document/abi-spec.json | 73 ------------ .../java/com/yahoo/document/BucketIdFactory.java | 7 -- .../com/yahoo/document/idstring/DocIdString.java | 2 + .../yahoo/document/idstring/GroupDocIdString.java | 64 ---------- .../java/com/yahoo/document/idstring/IdString.java | 101 ++-------------- .../yahoo/document/idstring/OrderDocIdString.java | 116 ------------------ .../yahoo/document/idstring/UserDocIdString.java | 59 ---------- document/src/vespa/document/base/idstring.cpp | 129 +-------------------- document/src/vespa/document/base/idstring.h | 89 +------------- document/src/vespa/document/bucket/bucketid.h | 3 +- .../src/vespa/document/bucket/bucketselector.cpp | 40 +++---- 11 files changed, 25 insertions(+), 658 deletions(-) delete mode 100644 document/src/main/java/com/yahoo/document/idstring/GroupDocIdString.java delete mode 100644 document/src/main/java/com/yahoo/document/idstring/OrderDocIdString.java delete mode 100644 document/src/main/java/com/yahoo/document/idstring/UserDocIdString.java (limited to 'document') diff --git a/document/abi-spec.json b/document/abi-spec.json index 9500a837a16..fc44686ad60 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -3461,21 +3461,6 @@ ], "fields": [] }, - "com.yahoo.document.idstring.GroupDocIdString": { - "superClass": "com.yahoo.document.idstring.IdString", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void (java.lang.String, java.lang.String, java.lang.String)", - "public long getLocation()", - "public java.lang.String getSchemeSpecific()", - "public boolean hasGroup()", - "public java.lang.String getGroup()" - ], - "fields": [] - }, "com.yahoo.document.idstring.IdIdString": { "superClass": "com.yahoo.document.idstring.IdString", "interfaces": [], @@ -3497,20 +3482,6 @@ ], "fields": [] }, - "com.yahoo.document.idstring.IdString$GidModifier": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void (com.yahoo.document.idstring.IdString)" - ], - "fields": [ - "public int usedBits", - "public long value" - ] - }, "com.yahoo.document.idstring.IdString$Scheme": { "superClass": "java.lang.Enum", "interfaces": [], @@ -3525,9 +3496,6 @@ ], "fields": [ "public static final enum com.yahoo.document.idstring.IdString$Scheme doc", - "public static final enum com.yahoo.document.idstring.IdString$Scheme userdoc", - "public static final enum com.yahoo.document.idstring.IdString$Scheme groupdoc", - "public static final enum com.yahoo.document.idstring.IdString$Scheme orderdoc", "public static final enum com.yahoo.document.idstring.IdString$Scheme id" ] }, @@ -3545,7 +3513,6 @@ "public boolean hasNumber()", "public long getNumber()", "public java.lang.String getGroup()", - "public static int[] generateOrderDocParams(java.lang.String)", "public static com.yahoo.document.idstring.IdString createIdString(java.lang.String)", "public static com.yahoo.document.idstring.IdString createFromSerialized(java.lang.String)", "protected void (com.yahoo.document.idstring.IdString$Scheme, java.lang.String, java.lang.String)", @@ -3555,7 +3522,6 @@ "public abstract long getLocation()", "public java.lang.String getSchemeParameters()", "public abstract java.lang.String getSchemeSpecific()", - "public com.yahoo.document.idstring.IdString$GidModifier getGidModifier()", "public boolean equals(java.lang.Object)", "public int hashCode()", "public java.lang.String toString()", @@ -3563,45 +3529,6 @@ ], "fields": [] }, - "com.yahoo.document.idstring.OrderDocIdString": { - "superClass": "com.yahoo.document.idstring.IdString", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void (java.lang.String, java.lang.String, int, int, long, java.lang.String)", - "public long getLocation()", - "public java.lang.String getSchemeParameters()", - "public java.lang.String getSchemeSpecific()", - "public com.yahoo.document.idstring.IdString$GidModifier getGidModifier()", - "public boolean hasGroup()", - "public java.lang.String getGroup()", - "public boolean hasNumber()", - "public long getNumber()", - "public long getUserId()", - "public int getWidthBits()", - "public int getDivisionBits()", - "public long getOrdering()" - ], - "fields": [] - }, - "com.yahoo.document.idstring.UserDocIdString": { - "superClass": "com.yahoo.document.idstring.IdString", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void (java.lang.String, long, java.lang.String)", - "public boolean hasNumber()", - "public long getNumber()", - "public long getLocation()", - "public java.lang.String getSchemeSpecific()", - "public long getUserId()" - ], - "fields": [] - }, "com.yahoo.document.serialization.AnnotationReader": { "superClass": "java.lang.Object", "interfaces": [], diff --git a/document/src/main/java/com/yahoo/document/BucketIdFactory.java b/document/src/main/java/com/yahoo/document/BucketIdFactory.java index 7ff09dd62e9..8ae769dbb11 100644 --- a/document/src/main/java/com/yahoo/document/BucketIdFactory.java +++ b/document/src/main/java/com/yahoo/document/BucketIdFactory.java @@ -89,15 +89,8 @@ public class BucketIdFactory { public BucketId getBucketId(DocumentId doc) { long location = doc.getScheme().getLocation(); byte[] gid = doc.getGlobalId(); - long gidContribution = getGidContribution(gid); - IdString.GidModifier gm = doc.getScheme().getGidModifier(); - if (gm != null && gm.usedBits != 0) { - gidContribution &= (0xFFFFFFFFFFFFFFFFl << (gm.usedBits + getLocationBitCount())); - gidContribution |= (gm.value << getLocationBitCount()); - } - return new BucketId(64 - BucketId.COUNT_BITS, initialCount | (gidMask & gidContribution) | (locationMask & location)); } diff --git a/document/src/main/java/com/yahoo/document/idstring/DocIdString.java b/document/src/main/java/com/yahoo/document/idstring/DocIdString.java index 7ce9d6150e2..09cc27d2c89 100644 --- a/document/src/main/java/com/yahoo/document/idstring/DocIdString.java +++ b/document/src/main/java/com/yahoo/document/idstring/DocIdString.java @@ -12,6 +12,8 @@ import java.security.NoSuchAlgorithmException; * * @author Einar M R Rosenvinge */ +//TODO Remove no later than Vespa 8 +@Deprecated public class DocIdString extends IdString { /** * Create a doc scheme object. diff --git a/document/src/main/java/com/yahoo/document/idstring/GroupDocIdString.java b/document/src/main/java/com/yahoo/document/idstring/GroupDocIdString.java deleted file mode 100644 index ff975efa274..00000000000 --- a/document/src/main/java/com/yahoo/document/idstring/GroupDocIdString.java +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.idstring; - -import com.yahoo.collections.MD5; -import com.yahoo.text.Utf8; - -import java.security.MessageDigest; - -/** - * Representation of groupdoc scheme in document IDs. - * - * @author Håkon Humberset - */ -public class GroupDocIdString extends IdString { - String group; - - /** - * Create a groupdoc scheme object. - * groupdoc:<namespace>:<group>:<namespaceSpecific> - * - * @param namespace The namespace of this document id. - * @param group The groupname of this groupdoc id. - * @param namespaceSpecific The namespace specific part. - */ - public GroupDocIdString(String namespace, String group, String namespaceSpecific) { - super(Scheme.groupdoc, namespace, namespaceSpecific); - this.group = group; - } - - /** - * Get the location of this document id. The location is used for distribution - * in clusters. For the groupdoc scheme, the location is a hash of the groupname. - * - * @return The 64 bit location. - */ - public long getLocation() { - long result = 0; - try{ - byte[] md5sum = MD5.md5.get().digest(Utf8.toBytes(group)); - for (int i=0; i<8; ++i) { - result |= (md5sum[i] & 0xFFl) << (8*i); - } - } catch (Exception e) { - e.printStackTrace(); // TODO: FIXME! - } - return result; - } - - /** Get the scheme specific part. Which is for a groupdoc, is the groupdoc and a colon. */ - public String getSchemeSpecific() { - return group + ":"; - } - - @Override - public boolean hasGroup() { - return true; - } - - /** @return Get the groupname of this id. */ - @Override - public String getGroup() { - return group; - } -} diff --git a/document/src/main/java/com/yahoo/document/idstring/IdString.java b/document/src/main/java/com/yahoo/document/idstring/IdString.java index 0ca26f29e86..d988de60cdf 100644 --- a/document/src/main/java/com/yahoo/document/idstring/IdString.java +++ b/document/src/main/java/com/yahoo/document/idstring/IdString.java @@ -4,9 +4,6 @@ package com.yahoo.document.idstring; import com.yahoo.text.Text; import com.yahoo.text.Utf8String; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.OptionalInt; /** @@ -40,42 +37,11 @@ public abstract class IdString { return ""; } - public class GidModifier { - public int usedBits; - public long value; - } - - public enum Scheme { doc, userdoc, groupdoc, orderdoc, id } - final Scheme scheme; - final String namespace; - final String namespaceSpecific; - Utf8String cache; - - public static int[] generateOrderDocParams(String scheme) { - int parenPos = scheme.indexOf("("); - int endParenPos = scheme.indexOf(")"); - - if (parenPos == -1 || endParenPos == -1) { - throw new IllegalArgumentException("Unparseable scheme " + scheme + ": Must be on the form orderdoc(width, division)"); - } - - String params = scheme.substring(parenPos + 1, endParenPos); - String[] vals = params.split(","); - - if (vals.length != 2) { - throw new IllegalArgumentException("Unparseable scheme " + scheme + ": Must be on the form orderdoc(width, division)"); - } - - int[] retVal = new int[2]; - - try { - retVal[0] = Integer.parseInt(vals[0]); - retVal[1] = Integer.parseInt(vals[1]); - return retVal; - } catch (Exception e) { - throw new IllegalArgumentException("Unparseable scheme " + scheme + ": Must be on the form orderdoc(width, division)"); - } - } + public enum Scheme { doc, id } + private final Scheme scheme; + private final String namespace; + private final String namespaceSpecific; + private Utf8String cache; /** * Creates a IdString based on the given document id string. @@ -113,11 +79,9 @@ public abstract class IdString { } } + @SuppressWarnings("deprecation") private static IdString parseAndCreate(String id) { String namespace; - long userId; - String group; - long ordering; int schemePos = id.indexOf(":"); if (schemePos < 0) { @@ -158,58 +122,8 @@ public abstract class IdString { currPos = colonPos + 1; return new IdIdString(namespace, type, keyValues, id.substring(currPos)); - } if (schemeStr.equals("doc")) { + } else if (schemeStr.equals("doc")) { return new DocIdString(namespace, id.substring(currPos)); - } else if (schemeStr.equals("userdoc")) { - colonPos = id.indexOf(":", currPos); - if (colonPos < 0) { - throw new IllegalArgumentException("Unparseable id '" + id + "': User id missing"); - } - - try { - userId = new BigInteger(id.substring(currPos, colonPos)).longValue(); - } catch (IllegalArgumentException iae) { - throw new IllegalArgumentException("Unparseable id '" + id + "': " + iae.getMessage(), iae.getCause()); - } - - currPos = colonPos + 1; - return new UserDocIdString(namespace, userId, id.substring(currPos)); - } else if (schemeStr.equals("groupdoc")) { - colonPos = id.indexOf(":", currPos); - - if (colonPos < 0) { - throw new IllegalArgumentException("Unparseable id '" + id + "': Group id missing"); - } - - group = id.substring(currPos, colonPos); - currPos = colonPos + 1; - return new GroupDocIdString(namespace, group, id.substring(currPos)); - } else if (schemeStr.indexOf("orderdoc") == 0) { - int[] params = generateOrderDocParams(schemeStr); - - colonPos = id.indexOf(":", currPos); - - if (colonPos < 0) { - throw new IllegalArgumentException("Unparseable id '" + id + "': Group id missing"); - } - - group = id.substring(currPos, colonPos); - - currPos = colonPos + 1; - - colonPos = id.indexOf(":", currPos); - if (colonPos < 0) { - throw new IllegalArgumentException("Unparseable id '" + id + "': Ordering missing"); - } - - try { - ordering = Long.parseLong(id.substring(currPos, colonPos)); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Unparseable id '" + id + "': " + e.getMessage(), e.getCause()); - } - - currPos = colonPos + 1; - return new OrderDocIdString(namespace, group, params[0], params[1], ordering, id.substring(currPos)); } else { throw new IllegalArgumentException("Unknown id scheme '" + schemeStr + "'"); } @@ -228,7 +142,6 @@ public abstract class IdString { public abstract long getLocation(); public String getSchemeParameters() { return ""; } public abstract String getSchemeSpecific(); - public GidModifier getGidModifier() { return null; } public boolean equals(Object o) { return (o instanceof IdString && o.toString().equals(toString())); diff --git a/document/src/main/java/com/yahoo/document/idstring/OrderDocIdString.java b/document/src/main/java/com/yahoo/document/idstring/OrderDocIdString.java deleted file mode 100644 index 8c9ec506249..00000000000 --- a/document/src/main/java/com/yahoo/document/idstring/OrderDocIdString.java +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.idstring; - -import com.yahoo.collections.MD5; -import com.yahoo.text.Utf8; - -import java.security.MessageDigest; - -/** - * Representation of groupdoc scheme in document IDs. - * - * @author Håkon Humberset - */ -public class OrderDocIdString extends IdString { - String group; - int widthBits; - int divisionBits; - long ordering; - long location; - - /** - * Create a groupdoc scheme object. - * groupdoc:<namespace>:<group>:<namespaceSpecific> - * - * @param namespace The namespace of this document id. - * @param group The groupname of this groupdoc id. - * @param widthBits The number of bits used for the width of the data set - * @param divisionBits The number of bits used for the smalles partitioning of the data set - * @param ordering A value used to order documents of this type. - * @param namespaceSpecific The namespace specific part. - */ - public OrderDocIdString(String namespace, String group, int widthBits, int divisionBits, long ordering, String namespaceSpecific) { - super(Scheme.orderdoc, namespace, namespaceSpecific); - this.group = group; - this.widthBits = widthBits; - this.divisionBits = divisionBits; - this.ordering = ordering; - - try { - this.location = Long.parseLong(group); - } catch (Exception foo) { - location = 0; - byte[] md5sum = MD5.md5.get().digest(Utf8.toBytes(group)); - for (int i=0; i<8; ++i) { - location |= (md5sum[i] & 0xFFl) << (8*i); - } - } - } - - /** - * Get the location of this document id. The location is used for distribution - * in clusters. For the orderdoc scheme, the location is a hash of the groupname or just the number specified. - * - * @return The 64 bit location. - */ - public long getLocation() { - return location; - } - - public String getSchemeParameters() { - return "(" + widthBits + "," + divisionBits + ")"; - } - - /** Get the scheme specific part. */ - public String getSchemeSpecific() { - return group + ":" + ordering + ":"; - } - - public GidModifier getGidModifier() { - GidModifier gm = new GidModifier(); - gm.usedBits = widthBits - divisionBits; - long gidBits = (ordering << (64 - widthBits)); - gidBits = Long.reverse(gidBits); - long gidMask = (0xFFFFFFFFFFFFFFFFl >>> (64 - gm.usedBits)); - gidBits &= gidMask; - gm.value = gidBits; - return gm; - } - - @Override - public boolean hasGroup() { - return true; - } - - /** @return Get the groupname of this id. */ - @Override - public String getGroup() { - return group; - } - - @Override - public boolean hasNumber() { - return true; - } - - @Override - public long getNumber() { - return location; - } - - public long getUserId() { - return location; - } - - public int getWidthBits() { - return widthBits; - } - - public int getDivisionBits() { - return divisionBits; - } - - public long getOrdering() { - return ordering; - } -} diff --git a/document/src/main/java/com/yahoo/document/idstring/UserDocIdString.java b/document/src/main/java/com/yahoo/document/idstring/UserDocIdString.java deleted file mode 100644 index 4da56bfbb6e..00000000000 --- a/document/src/main/java/com/yahoo/document/idstring/UserDocIdString.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.idstring; - -import java.math.BigInteger; - -/** - * Representation of userdoc scheme in document IDs. A user id is any 64 bit - * number. Note that internally, these are handled as unsigned values. - * - * @author Einar M R Rosenvinge - */ -public class UserDocIdString extends IdString { - long userId; - - /** - * Create a userdoc scheme object. - * userdoc:<namespace>:<userid>:<namespaceSpecific> - * - * @param namespace The namespace of this document id. - * @param userId 64 bit user id of this userdoc id. - * @param namespaceSpecific The namespace specific part. - */ - public UserDocIdString(String namespace, long userId, String namespaceSpecific) { - super(Scheme.userdoc, namespace, namespaceSpecific); - this.userId = userId; - } - - @Override - public boolean hasNumber() { - return true; - } - - @Override - public long getNumber() { - return userId; - } - - /** - * Get the location of this document id. The location is used for distribution - * in clusters. For the userdoc scheme, the location equals the user id. - * - * @return The 64 bit location. - */ - public long getLocation() { return userId; } - - /** Get the scheme specific part. Which for a userdoc, is the userid and a colon. */ - public String getSchemeSpecific() { - BigInteger uid = BigInteger.ZERO; - for (int i=0; i<64; i++) { - if ((userId >>> i & 0x1) == 1) { - uid = uid.setBit(i); - } - } - return uid.toString() + ":"; - } - - /** @return Get the user id of this id. */ - public long getUserId() { return userId; } -} diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp index 5166b03428e..785a56a4e45 100644 --- a/document/src/vespa/document/base/idstring.cpp +++ b/document/src/vespa/document/base/idstring.cpp @@ -20,9 +20,6 @@ namespace { string _G_typeName[6] = { "doc", - "userdoc", - "groupdoc", - "orderdoc", "id", "null" }; @@ -50,8 +47,6 @@ IdString::toString() const namespace { void reportError(const char* part) __attribute__((noinline)); -void reportError(stringref s) __attribute__((noinline)); -void reportError(stringref s, const char* part) __attribute__((noinline)); void reportTooShortDocId(const char * id, size_t sz) __attribute__((noinline)); void reportNoSchemeSeparator(const char * id) __attribute__((noinline)); @@ -59,16 +54,7 @@ void reportError(const char* part) { throw IdParseException(make_string("Unparseable id: No %s separator ':' found", part), VESPA_STRLOC); } -void reportError(stringref s, const char* part) -{ - throw IdParseException(make_string("Unparseable %s '%s': Not an unsigned 64-bit number", part, string(s).c_str()), VESPA_STRLOC); -} -void reportError(stringref s) -{ - throw IdParseException(make_string("Unparseable order doc scheme '%s': Scheme must contain parameters on the form (width, division)", - string(s).c_str()), VESPA_STRLOC); -} void reportNoSchemeSeparator(const char * id) { throw IdParseException(make_string("Unparseable id '%s': No scheme separator ':' found", id), VESPA_STRLOC); @@ -79,49 +65,6 @@ void reportTooShortDocId(const char * id, size_t sz) throw IdParseException( make_string( "Unparseable id '%s': It is too short(%li) " "to make any sense", id, sz), VESPA_STRLOC); } -uint64_t getAsNumber(stringref s, const char* part) { - char* errPos = NULL; - uint64_t value = strtoull(s.data(), &errPos, 10); - - if (s.data() + s.size() != errPos) { - reportError(s, part); - } - return value; -} - -void -getOrderDocBits(stringref scheme, uint16_t & widthBits, uint16_t & divisionBits) -{ - const char* parenPos = reinterpret_cast( - memchr(scheme.data(), '(', scheme.size())); - const char* endParenPos = reinterpret_cast( - memchr(scheme.data(), ')', scheme.size())); - - if (parenPos == NULL || endParenPos == NULL || endParenPos < parenPos) { - reportError(scheme); - } - - const char* separatorPos = reinterpret_cast( - memchr(parenPos + 1, ',', endParenPos - parenPos - 1)); - if (separatorPos == NULL) { - reportError(scheme); - } - - char* endptr = NULL; - // strtoul stops at first non-numeric char (in this case ',' and ')'), so don't - // require any extra zero-terminated buffers - errno = 0; - widthBits = static_cast(strtoul(parenPos + 1, &endptr, 10)); - if (errno != 0 || *endptr != ',') { - reportError(scheme); - } - errno = 0; - divisionBits = static_cast(strtoul(separatorPos + 1, &endptr, 10)); - if (errno != 0 || *endptr != ')') { - reportError(scheme); - } -} - union TwoByte { char asChar[2]; uint16_t as16; @@ -139,9 +82,6 @@ union EightByte { const FourByte _G_doc = {{'d', 'o', 'c', ':'}}; const FourByte _G_null = {{'n', 'u', 'l', 'l'}}; -const EightByte _G_userdoc = {{'u', 's', 'e', 'r', 'd', 'o', 'c', ':'}}; -const EightByte _G_groupdoc = {{'g', 'r', 'o', 'u', 'p', 'd', 'o', 'c'}}; -const EightByte _G_orderdoc = {{'o', 'r', 'd', 'e', 'r', 'd', 'o', 'c'}}; const TwoByte _G_id = {{'i', 'd'}}; typedef char v16qi __attribute__ ((__vector_size__(16))); @@ -252,15 +192,7 @@ IdString::createIdString(const char * id, size_t sz_) } else if (_G_id.as16 == *reinterpret_cast(id) && id[2] == ':') { return IdString::UP(new IdIdString(stringref(id, sz_))); } else if (sz_ > 8) { - if (_G_userdoc.as64 == *reinterpret_cast(id)) { - return IdString::UP(new UserDocIdString(stringref(id, sz_))); - } else if (_G_groupdoc.as64 == *reinterpret_cast(id) && (id[8] == ':')) { - return IdString::UP(new GroupDocIdString(stringref(id, sz_))); - } else if (_G_orderdoc.as64 == *reinterpret_cast(id) && (id[8] == '(')) { - return IdString::UP(new OrderDocIdString(stringref(id, sz_))); - } else { - reportNoSchemeSeparator(id); - } + reportNoSchemeSeparator(id); } else { reportTooShortDocId(id, 8); } @@ -357,12 +289,6 @@ DocIdString::getLocation() const return makeLocation(toString()); } -IdString::LocationType -GroupDocIdString::getLocation() const -{ - return makeLocation(getGroup()); -} - DocIdString::DocIdString(stringref ns, stringref id) : IdString(2, 4, "doc:" + ns + ":" + id) { @@ -375,57 +301,4 @@ DocIdString::DocIdString(stringref rawId) : validate(); } -UserDocIdString::UserDocIdString(stringref rawId) : - IdString(3, 8, rawId), - _userId(getAsNumber(rawId.substr(offset(1), offset(2) - offset(1) - 1), "userid")) -{ - validate(); -} - -GroupDocIdString::GroupDocIdString(stringref rawId) : - IdString(3, 9, rawId) -{ - validate(); -} - -IdString::LocationType -GroupDocIdString::locationFromGroupName(vespalib::stringref name) -{ - return makeLocation(name); -} - -OrderDocIdString::OrderDocIdString(stringref rawId) : - IdString(4, static_cast(memchr(rawId.data(), ':', rawId.size())) - rawId.data() + 1, rawId), - _widthBits(0), - _divisionBits(0), - _ordering(getAsNumber(rawId.substr(offset(2), offset(3) - offset(2) - 1), "ordering")) -{ - validate(); - getOrderDocBits(rawId.substr(0, offset(0) - 1), _widthBits, _divisionBits); - - string group(rawId.substr(offset(1), offset(2) - offset(1) - 1)); - char* errStr = NULL; - _location = strtoull(group.c_str(), &errStr, 0); - if (*errStr != '\0') { - LocationUnion location; - fastc_md5sum((const unsigned char*) group.c_str(), group.size(), location._key); - _location = location._location[0]; - } -} - -std::pair -OrderDocIdString::getGidBitsOverride() const -{ - int usedBits = _widthBits - _divisionBits; - int64_t gidBits = (_ordering << (64 - _widthBits)); - gidBits = BucketId::reverse(gidBits); - gidBits &= (std::numeric_limits::max() >> (64 - usedBits)); - return std::pair(usedBits, gidBits); -} - -string -OrderDocIdString::getSchemeName() const { - return make_string("%s(%d,%d)", getTypeName(getType()).c_str(), _widthBits, _divisionBits); -} - } // document diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h index c77289fd659..55ff767a3ff 100644 --- a/document/src/vespa/document/base/idstring.h +++ b/document/src/vespa/document/base/idstring.h @@ -20,7 +20,7 @@ public: typedef std::unique_ptr UP; typedef vespalib::CloneablePtr CP; typedef uint64_t LocationType; - enum Type { DOC=0, USERDOC, GROUPDOC, ORDERDOC, ID, NULLID }; + enum Type { DOC=0, ID, NULLID }; static const vespalib::string & getTypeName(Type t); /** @throws document::IdParseException If parsing of id scheme failed. */ @@ -138,91 +138,4 @@ private: vespalib::stringref getNamespaceSpecific() const override { return getComponent(1); } }; -/** - * \class document::UserDocIdString - * \ingroup base - * - * \brief Scheme for distributing documents based on a 64 bit number. - * - * The location of a userdoc identifier is the 64 bit id given. The - * name "userdoc" is purely syntactical; Vespa does not care what the source - * of the number is. - */ -class UserDocIdString final : public IdString { -public: - UserDocIdString(vespalib::stringref rawId); - - virtual int64_t getUserId() const { return _userId; } - bool hasNumber() const override { return true; } - uint64_t getNumber() const override { return _userId; } - LocationType getLocation() const override { return _userId; } - -private: - UserDocIdString* clone() const override { return new UserDocIdString(*this); } - Type getType() const override { return USERDOC; } - vespalib::stringref getNamespaceSpecific() const override { return getComponent(2); } - - int64_t _userId; -}; - -/** - * \class document::OrderDocIdString - * \ingroup base - * \brief Scheme for distributing documents based on a group and a parametrized ordering. - */ -class OrderDocIdString final : public IdString { -public: - OrderDocIdString(vespalib::stringref rawId); - - int64_t getUserId() const { return _location; } - uint16_t getWidthBits() const { return _widthBits; } - uint16_t getDivisionBits() const { return _divisionBits; } - uint64_t getOrdering() const { return _ordering; } - std::pair getGidBitsOverride() const override; - vespalib::string getSchemeName() const override; - bool hasNumber() const override { return true; } - uint64_t getNumber() const override { return _location; } - bool hasGroup() const override { return true; } - vespalib::stringref getGroup() const override { return getComponent(1); } - -private: - LocationType getLocation() const override { return _location; } - OrderDocIdString* clone() const override { return new OrderDocIdString(*this); } - Type getType() const override { return ORDERDOC; } - vespalib::stringref getNamespaceSpecific() const override { return getComponent(3); } - - LocationType _location; - uint16_t _widthBits; - uint16_t _divisionBits; - uint64_t _ordering; -}; - -/** - * \class document::GroupDocIdString - * \ingroup base - * - * \brief Scheme for distributing documents based on a group string. - * - * The location of a groupdoc identifier is a hash of the group string. - */ -class GroupDocIdString : public IdString { -public: - GroupDocIdString(vespalib::stringref rawId); - bool hasGroup() const override { return true; } - vespalib::stringref getGroup() const override { return getComponent(1); } - LocationType getLocation() const override; - - /** - * Extract the location for the group-specific part of a document ID. - * i.e. `name` here must match the `group` in ID "id::foo:g=group:". - */ - static LocationType locationFromGroupName(vespalib::stringref name); - -private: - vespalib::stringref getNamespaceSpecific() const override { return getComponent(2); } - GroupDocIdString* clone() const override { return new GroupDocIdString(*this); } - Type getType() const override { return GROUPDOC; } -}; - } // document - diff --git a/document/src/vespa/document/bucket/bucketid.h b/document/src/vespa/document/bucket/bucketid.h index 2f1cb58bf31..0f8e3f23f7d 100644 --- a/document/src/vespa/document/bucket/bucketid.h +++ b/document/src/vespa/document/bucket/bucketid.h @@ -12,8 +12,7 @@ * - The 32 LSB bits are the location. This part may be overridden by * document id schemes to create a first level sorting criteria. * - The remaining 28 bits are GID bits (calculated from MD5), used to split - * up buckets with the same location bits. Orderdoc overrides some of these - * bits to represent a secondary order. + * up buckets with the same location bits. * * Bucket identifiers are created by the bucket id factory, such that some * non-static state can be kept to optimize the generation. diff --git a/document/src/vespa/document/bucket/bucketselector.cpp b/document/src/vespa/document/bucket/bucketselector.cpp index c4e0bc06a3d..62352718444 100644 --- a/document/src/vespa/document/bucket/bucketselector.cpp +++ b/document/src/vespa/document/bucket/bucketselector.cpp @@ -81,51 +81,39 @@ using namespace document::select; const select::Operator& op) { if (node.getType() == IdValueNode::ALL) { - const StringValueNode* val( - dynamic_cast(&valnode)); + auto val = dynamic_cast(&valnode); if (!val) return; vespalib::string docId(val->getValue()); - if (op == FunctionOperator::EQ || - !GlobOperator::containsVariables(docId)) - { + if (op == FunctionOperator::EQ || !GlobOperator::containsVariables(docId)) { IdString::UP id(IdString::createIdString(docId)); _buckets.push_back(BucketId(58, id->getLocation())); _unknown = false; } } else if (node.getType() == IdValueNode::USER) { - const IntegerValueNode* val( - dynamic_cast(&valnode)); + auto val = dynamic_cast(&valnode); if (!val) return; - UserDocIdString id(vespalib::make_string("userdoc::%" PRIu64 ":", val->getValue())); - _buckets.push_back(BucketId(32, id.getLocation())); + IdIdString id(vespalib::make_string("id::test:n=%" PRIu64 ":", val->getValue())); + _buckets.push_back(BucketId(32, id.getNumber())); _unknown = false; } else if (node.getType() == IdValueNode::GROUP) { - const StringValueNode* val( - dynamic_cast(&valnode)); + auto val = dynamic_cast(&valnode); if (!val) return; vespalib::string group(val->getValue()); - if (op == FunctionOperator::EQ || - !GlobOperator::containsVariables(group)) - { - GroupDocIdString id("groupdoc::" + group + ":"); - _buckets.push_back(BucketId(32, id.getLocation())); + if (op == FunctionOperator::EQ || !GlobOperator::containsVariables(group)) { + _buckets.push_back(BucketId(32, IdString::makeLocation(group))); _unknown = false; } } else if (node.getType() == IdValueNode::GID) { - const StringValueNode* val( - dynamic_cast(&valnode)); + auto val = dynamic_cast(&valnode); vespalib::string gid(val->getValue()); - if (op == FunctionOperator::EQ || - !GlobOperator::containsVariables(gid)) - { + if (op == FunctionOperator::EQ || !GlobOperator::containsVariables(gid)) { BucketId bid = document::GlobalId::parse(gid).convertToBucketId(); _buckets.push_back(BucketId(32, bid.getRawId())); _unknown = false; } } else if (node.getType() == IdValueNode::BUCKET) { - const IntegerValueNode* val( - dynamic_cast(&valnode)); + auto val = dynamic_cast(&valnode); if (!val) return; BucketId bid(val->getValue()); @@ -143,13 +131,11 @@ using namespace document::select; { return; } - const IdValueNode* lid(dynamic_cast( - &node.getLeft())); + auto lid = dynamic_cast(&node.getLeft()); if (lid) { compare(*lid, node.getRight(), node.getOperator()); } else { - const IdValueNode* rid(dynamic_cast( - &node.getRight())); + auto rid = dynamic_cast(&node.getRight()); if (rid) { compare(*rid, node.getLeft(), node.getOperator()); } -- cgit v1.2.3