Skip to content

Commit

Permalink
Merge pull request #21484 from vespa-engine/bratseth/cleanup-0923
Browse files Browse the repository at this point in the history
No functional changes
  • Loading branch information
jonmv authored Mar 1, 2022
2 parents 2e1a887 + 0b59d84 commit 3b60f8a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;

import com.yahoo.document.BucketId;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -14,7 +12,7 @@
public class BucketDistribution {

// A logger object to enable proper logging.
private static Logger log = Logger.getLogger(BucketDistribution.class.getName());
private static final Logger log = Logger.getLogger(BucketDistribution.class.getName());

// A map from bucket id to column index.
private int[] bucketToColumn;
Expand Down
27 changes: 11 additions & 16 deletions document/src/main/java/com/yahoo/document/DocumentId.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
import com.yahoo.vespa.objects.Serializer;

import java.io.Serializable;
import java.util.Objects;

/**
* The id of a document
*/
public class DocumentId extends Identifiable implements Serializable {

private IdString id;
private GlobalId globalId;
private GlobalId globalId = null;

/**
* Constructor used for deserialization.
*/
/** Constructor used for deserialization. */
public DocumentId(Deserializer buf) {
deserialize(buf);
}
Expand All @@ -33,21 +32,14 @@ public DocumentId(Deserializer buf) {
* The document id string can only contain text characters.
*/
public DocumentId(String id) {
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(" + IdString.MAX_LENGTH + "). " +
"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;
this.id = IdString.createIdString(Objects.requireNonNull(id));
if (id.length() > IdString.MAX_LENGTH)
throw new IllegalArgumentException("Document id of length " + id.length() +
" is longer than the max " + IdString.MAX_LENGTH);
}

public DocumentId(IdString id) {
this.id = id;
globalId = null;
}

/**
Expand Down Expand Up @@ -86,14 +78,17 @@ public int compareTo(Object o) {
return id.toString().compareTo(cmp.id.toString());
}

@Override
public boolean equals(Object o) {
return o instanceof DocumentId && id.equals(((DocumentId)o).id);
}

@Override
public int hashCode() {
return id.hashCode();
}

@Override
public String toString() {
return id.toString();
}
Expand All @@ -107,7 +102,6 @@ public void onSerialize(Serializer target) throws SerializationException {
}
}


public void onDeserialize(Deserializer data) throws DeserializationException {
if (data instanceof DocumentReader) {
id = ((DocumentReader)data).readDocumentId().getScheme();
Expand All @@ -123,4 +117,5 @@ public boolean hasDocType() {
public String getDocType() {
return id.getDocType();
}

}
8 changes: 4 additions & 4 deletions document/src/main/java/com/yahoo/document/GlobalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public GlobalId(byte[] raw) {
/**
* Constructs a new global id from a document id string.
*
* @param id The document id to derive from.
* @param id the document id to derive from
*/
public GlobalId(IdString id) {
byte [] raw = MD5.md5.get().digest(id.toUtf8().wrap().array());
byte[] raw = MD5.md5.get().digest(id.toUtf8().wrap().array());
long location = id.getLocation();
this.raw = new byte [LENGTH];
for (int i = 0; i < 4; ++i) {
Expand All @@ -57,7 +57,7 @@ public GlobalId(IdString id) {
/**
* Constructs a global id by deserializing content from the given byte buffer.
*
* @param buf The buffer to deserialize from.
* @param buf the buffer to deserialize from
*/
public GlobalId(Deserializer buf) {
raw = buf.getBytes(null, LENGTH);
Expand All @@ -66,7 +66,7 @@ public GlobalId(Deserializer buf) {
/**
* Serializes the content of this global id into the given byte buffer.
*
* @param buf The buffer to serialize to.
* @param buf the buffer to serialize to
*/
public void serialize(Serializer buf) {
buf.put(null, raw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ public void testTooLongDocId() {
new DocumentId(sb.toString());
fail("Expected an IllegalArgumentException to be thrown");
} catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().contains("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."));
assertEquals("Document id length 65548 is longer than max length of 65536", ex.getMessage());
}
assertEquals(65548, new DocumentId(IdString.createIdStringLessStrict(sb.toString())).toString().length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public DocumentV1ApiHandler(Metric metric,
this.operations = new ConcurrentLinkedDeque<>();
long resendDelayMS = SystemTimer.adjustTimeoutByDetectedHz(Duration.ofMillis(executorConfig.resendDelayMillis())).toMillis();

//TODO Here it would be better do have dedicated threads with different wait depending on blocked or empty.
// TODO: Here it would be better do have dedicated threads with different wait depending on blocked or empty.
this.dispatcher.scheduleWithFixedDelay(this::dispatchEnqueued, resendDelayMS, resendDelayMS, MILLISECONDS);
this.visitDispatcher.scheduleWithFixedDelay(this::dispatchVisitEnqueued, resendDelayMS, resendDelayMS, MILLISECONDS);
}
Expand Down

0 comments on commit 3b60f8a

Please sign in to comment.