aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-01-11 18:34:22 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-01-11 18:34:22 +0000
commit55b8a24439e9dc41122a98bd7537968983e8a9ec (patch)
tree3d5339fc449acc2e791bd1722a98939185ed266f /document/src/main
parent9043ed4ac5f1c8a4af91b1e2b2ff602bc1963c27 (diff)
Apply a 64k limit to documentids.
Diffstat (limited to 'document/src/main')
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentId.java8
-rw-r--r--document/src/main/java/com/yahoo/document/idstring/IdString.java17
2 files changed, 22 insertions, 3 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentId.java b/document/src/main/java/com/yahoo/document/DocumentId.java
index e7c904cc420..30ca9be8231 100644
--- a/document/src/main/java/com/yahoo/document/DocumentId.java
+++ b/document/src/main/java/com/yahoo/document/DocumentId.java
@@ -33,6 +33,11 @@ public class DocumentId extends Identifiable implements Serializable {
if (id == null) {
throw new IllegalArgumentException("Cannot create DocumentId from null id.");
}
+ if (id.length() > IdString.MAX_LENGTH) {
+ throw new IllegalArgumentException("The document id(" + id.length() + ") is too long(65536). " +
+ "However if you have already fed a document earlier on and want to remove it, you can do so by " +
+ "calling new DocumentId(IdString.createIdStringLessStrict()) that will bypass this restriction.");
+ }
this.id = IdString.createIdString(id);
globalId = null;
}
@@ -55,8 +60,7 @@ public class DocumentId extends Identifiable implements Serializable {
@Override
public DocumentId clone() {
- DocumentId docId = (DocumentId)super.clone();
- return docId;
+ return (DocumentId)super.clone();
}
public void setId(IdString id) {
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 2114a480ec3..404db928f30 100644
--- a/document/src/main/java/com/yahoo/document/idstring/IdString.java
+++ b/document/src/main/java/com/yahoo/document/idstring/IdString.java
@@ -1,6 +1,7 @@
// 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.google.common.annotations.Beta;
import com.yahoo.text.Text;
import com.yahoo.text.Utf8String;
@@ -43,7 +44,8 @@ public abstract class IdString {
private final String namespaceSpecific;
private Utf8String cache;
// This max unsigned 16 bit integer - 1 as the offset will be length + 1
- static final int MAX_LENGTH_EXCEPT_NAMESPACE_SPECIFIC = 0xfffe;
+ static final int MAX_LENGTH_EXCEPT_NAMESPACE_SPECIFIC = 0xff00;
+ public static final int MAX_LENGTH = 0x10000;
/**
* Creates a IdString based on the given document id string.
@@ -51,6 +53,19 @@ public abstract class IdString {
* The document id string can only contain text characters.
*/
public static IdString createIdString(String id) {
+ if (id.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("Document id length " + id.length() + " is longer than max length of " + MAX_LENGTH);
+ }
+ validateTextString(id);
+ return parseAndCreate(id);
+ }
+
+ /**
+ * Creates a IdString based on the given document id string. This is a less strict variant
+ * for creating 'illegal' document ids for documents already fed. Only use when strictly needed.
+ */
+ @Beta
+ public static IdString createIdStringLessStrict(String id) {
validateTextString(id);
return parseAndCreate(id);
}