From 923399a03316b8cc7acf5ffdf99426edf667ac6c Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Tue, 25 Sep 2018 13:52:38 +0200 Subject: Remove BatchDocumentUpdateMessage and BatchDocumentUpdateReply from java portion of documentapi. --- .../protocol/BatchDocumentUpdateMessage.java | 184 --------------------- .../protocol/BatchDocumentUpdateReply.java | 29 ---- .../messagebus/protocol/DocumentProtocol.java | 4 - .../protocol/DocumentRouteSelectorPolicy.java | 9 - .../messagebus/protocol/RoutableFactories50.java | 80 --------- .../messagebus/protocol/StoragePolicy.java | 1 - .../protocol/test/Messages50TestCase.java | 74 --------- 7 files changed, 381 deletions(-) delete mode 100644 documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateMessage.java delete mode 100755 documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateReply.java (limited to 'documentapi') diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateMessage.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateMessage.java deleted file mode 100644 index d8288a94ab6..00000000000 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateMessage.java +++ /dev/null @@ -1,184 +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.documentapi.messagebus.protocol; - -import com.yahoo.document.BucketId; -import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.DocumentId; -import com.yahoo.document.DocumentUpdate; -import com.yahoo.document.idstring.GroupDocIdString; -import com.yahoo.document.idstring.IdString; -import com.yahoo.document.idstring.UserDocIdString; -import com.yahoo.document.serialization.DocumentDeserializer; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Simon Thoresen Hult - */ -public class BatchDocumentUpdateMessage extends DocumentMessage { - - private DocumentDeserializer buffer = null; - private List updates = new ArrayList(); - private LazyDecoder decoder = null; - private String group = null; - private Long userId = null; - private BucketId bucketId = null; - - public String getGroup() { - return group; - } - - public Long getUserId() { - return userId; - } - - /** - * Constructs a new message for deserialization. - */ - BatchDocumentUpdateMessage() { - // empty - } - - /** - * Constructs a new message from a byte buffer. - * @param decoder The decoder to use for deserialization. - * @param buffer A byte buffer that contains a serialized message. - */ - public BatchDocumentUpdateMessage(long userId, LazyDecoder decoder, DocumentDeserializer buffer) { - this.userId = userId; - this.decoder = decoder; - this.buffer = buffer; - setBucketId(new UserDocIdString("foo", userId, "bar")); - } - - /** - * Constructs a new message from a byte buffer. - * @param decoder The decoder to use for deserialization. - * @param buffer A byte buffer that contains a serialized message. - */ - public BatchDocumentUpdateMessage(String group, LazyDecoder decoder, DocumentDeserializer buffer) { - this.group = group; - this.decoder = decoder; - this.buffer = buffer; - setBucketId(new GroupDocIdString("foo", group, "bar")); - } - - /** - * Constructs a batch document update message, to contain updates for documents for the given user. - */ - public BatchDocumentUpdateMessage(long userId) { - super(); - this.userId = userId; - setBucketId(new UserDocIdString("foo", userId, "bar")); - } - - /** - * Constructs a batch document update message, to contain updates for documents for the given user. - */ - public BatchDocumentUpdateMessage(String group) { - super(); - this.group = group; - setBucketId(new GroupDocIdString("foo", group, "bar")); - } - - void setBucketId(IdString id) { - BucketIdFactory factory = new BucketIdFactory(); - bucketId = factory.getBucketId(new DocumentId(id)); - } - - BucketId getBucketId() { - return bucketId; - } - - /** - * This method will make sure that any serialized content is deserialized into proper message content on first - * entry. Any subsequent entry into this function will do nothing. - */ - private void deserialize() { - if (decoder != null && buffer != null) { - decoder.decode(this, buffer); - decoder = null; - buffer = null; - } - } - - /** - * Returns the list of document updates to perform. - * - * @return The updates. - */ - public List getUpdates() { - deserialize(); - return updates; - } - - /** - * Adds a document update to perform. - * - * @param upd The document update to set. - */ - public void addUpdate(DocumentUpdate upd) { - buffer = null; - decoder = null; - - verifyUpdate(upd); - updates.add(upd); - } - - /** - * Returns the raw serialized buffer. This buffer is stored as the message is received from accross the network, and - * deserialized from as soon as a member is requested. This method will return null if the buffer has been decoded. - * - * @return The buffer containing the serialized data for this message, or null. - */ - ByteBuffer getSerializedBuffer() { - return buffer != null ? buffer.getBuf().getByteBuffer() : null; - } - - @Override - public DocumentReply createReply() { - return new BatchDocumentUpdateReply(); - } - - @Override - public int getType() { - return DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE; - } - - void verifyUpdate(DocumentUpdate update) { - if (update == null) { - throw new IllegalArgumentException("Document update can not be null."); - } - - IdString idString = update.getId().getScheme(); - - if (group != null) { - String idGroup; - - if (idString.hasGroup()) { - idGroup = idString.getGroup(); - } else { - throw new IllegalArgumentException("Batch update message can only contain groupdoc or orderdoc items"); - } - - if (!group.equals(idGroup)) { - throw new IllegalArgumentException("Batch update message can not contain messages from group " + idGroup + " only group " + group); - } - } else { - long foundUserId = 0; - - if (idString.hasNumber()) { - foundUserId = idString.getNumber(); - } else { - throw new IllegalArgumentException("Batch update message can only contain userdoc or orderdoc items"); - } - - if (userId != foundUserId) { - throw new IllegalArgumentException("Batch update message can not contain messages from user " + foundUserId + " only user " + userId); - } - } - } - -} diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateReply.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateReply.java deleted file mode 100755 index 3e6e3a3429d..00000000000 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/BatchDocumentUpdateReply.java +++ /dev/null @@ -1,29 +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.documentapi.messagebus.protocol; - -import java.util.ArrayList; - -public class BatchDocumentUpdateReply extends WriteDocumentReply { - - private ArrayList documentsNotFound = new ArrayList(); - - /** - * Constructs a new reply with no content. - */ - public BatchDocumentUpdateReply() { - super(DocumentProtocol.REPLY_BATCHDOCUMENTUPDATE); - } - - /** - * If all documents to update are found, this vector will be empty. If - * one or more documents are not found, this vector will have the size of - * the initial number of updates, with entries set to true where the - * corresponding update was not found. - * - * @return Vector containing indices of not found documents, or empty - * if all documents were found - */ - public ArrayList getDocumentsNotFound() { - return documentsNotFound; - } -} diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java index b765b928869..6983eb4fbd9 100755 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java @@ -66,7 +66,6 @@ public class DocumentProtocol implements Protocol { public static final int MESSAGE_EMPTYBUCKETS = DOCUMENT_MESSAGE + 23; public static final int MESSAGE_REMOVELOCATION = DOCUMENT_MESSAGE + 24; public static final int MESSAGE_QUERYRESULT = DOCUMENT_MESSAGE + 25; - public static final int MESSAGE_BATCHDOCUMENTUPDATE = DOCUMENT_MESSAGE + 26; /** * All reply types that are implemented by this protocol. @@ -89,7 +88,6 @@ public class DocumentProtocol implements Protocol { public static final int REPLY_EMPTYBUCKETS = DOCUMENT_REPLY + 23; public static final int REPLY_REMOVELOCATION = DOCUMENT_REPLY + 24; public static final int REPLY_QUERYRESULT = DOCUMENT_REPLY + 25; - public static final int REPLY_BATCHDOCUMENTUPDATE = DOCUMENT_REPLY + 26; public static final int REPLY_WRONGDISTRIBUTION = DOCUMENT_REPLY + 1000; public static final int REPLY_DOCUMENTIGNORED = DOCUMENT_REPLY + 1001; @@ -314,7 +312,6 @@ public class DocumentProtocol implements Protocol { List from6 = Collections.singletonList(version6); // TODO decide minor version... // 5.0 serialization (keep alphabetized please) - putRoutableFactory(MESSAGE_BATCHDOCUMENTUPDATE, new RoutableFactories50.BatchDocumentUpdateMessageFactory(), from50); putRoutableFactory(MESSAGE_CREATEVISITOR, new RoutableFactories50.CreateVisitorMessageFactory(), from50); putRoutableFactory(MESSAGE_DESTROYVISITOR, new RoutableFactories50.DestroyVisitorMessageFactory(), from50); putRoutableFactory(MESSAGE_DOCUMENTLIST, new RoutableFactories50.DocumentListMessageFactory(), from50); @@ -332,7 +329,6 @@ public class DocumentProtocol implements Protocol { putRoutableFactory(MESSAGE_STATBUCKET, new RoutableFactories50.StatBucketMessageFactory(), from50); putRoutableFactory(MESSAGE_UPDATEDOCUMENT, new RoutableFactories50.UpdateDocumentMessageFactory(), from50); putRoutableFactory(MESSAGE_VISITORINFO, new RoutableFactories50.VisitorInfoMessageFactory(), from50); - putRoutableFactory(REPLY_BATCHDOCUMENTUPDATE, new RoutableFactories50.BatchDocumentUpdateReplyFactory(), from50); putRoutableFactory(REPLY_CREATEVISITOR, new RoutableFactories50.CreateVisitorReplyFactory(), from50); putRoutableFactory(REPLY_DESTROYVISITOR, new RoutableFactories50.DestroyVisitorReplyFactory(), from50); putRoutableFactory(REPLY_DOCUMENTLIST, new RoutableFactories50.DocumentListReplyFactory(), from50); diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentRouteSelectorPolicy.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentRouteSelectorPolicy.java index e48026ae7d7..dbf4a6cc593 100755 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentRouteSelectorPolicy.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentRouteSelectorPolicy.java @@ -154,15 +154,6 @@ public class DocumentRouteSelectorPolicy } } - case DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE: - BatchDocumentUpdateMessage bdu = (BatchDocumentUpdateMessage)msg; - for (int i = 0; i < bdu.getUpdates().size(); i++) { - if (selector.accepts(bdu.getUpdates().get(i)) == Result.FALSE) { - return false; - } - } - return true; - default: return true; } diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactories50.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactories50.java index dfc87b77474..c7c1121ae68 100755 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactories50.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactories50.java @@ -583,86 +583,6 @@ public abstract class RoutableFactories50 { } } - public static class BatchDocumentUpdateMessageFactory extends DocumentMessageFactory { - - private final LazyDecoder decoder = new LazyDecoder() { - - public void decode(Routable obj, DocumentDeserializer buf) { - BatchDocumentUpdateMessage msg = (BatchDocumentUpdateMessage)obj; - int size = buf.getInt(null); - for (int i = 0; i < size; i++) { - msg.addUpdate(new DocumentUpdate(buf)); - } - } - }; - - @Override - protected DocumentMessage doDecode(DocumentDeserializer buf) { - long userId = buf.getLong(null); - String group = decodeString(buf); - - if (group.length() > 0) { - return new BatchDocumentUpdateMessage(group, decoder, buf); - } else { - return new BatchDocumentUpdateMessage(userId, decoder, buf); - } - } - - @Override - protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { - BatchDocumentUpdateMessage msg = (BatchDocumentUpdateMessage)obj; - - if (msg.getSerializedBuffer() != null) { - buf.put(null, msg.getSerializedBuffer()); - } else { - if (msg.getUserId() != null) { - buf.putLong(null, msg.getUserId()); - } else { - buf.putLong(null, 0); - } - - if (msg.getGroup() != null) { - encodeString(msg.getGroup(), buf); - } else { - encodeString("", buf); - } - - buf.putInt(null, msg.getUpdates().size()); - for (int i = 0; i < msg.getUpdates().size(); i++) { - msg.getUpdates().get(i).serialize(buf); - } - } - - return true; - } - } - - public static class BatchDocumentUpdateReplyFactory extends DocumentReplyFactory { - - @Override - protected DocumentReply doDecode(DocumentDeserializer buf) { - BatchDocumentUpdateReply rep = new BatchDocumentUpdateReply(); - rep.setHighestModificationTimestamp(buf.getLong(null)); - int size = buf.getInt(null); - rep.getDocumentsNotFound().ensureCapacity(size); - for (int i = 0; i < size; ++i) { - rep.getDocumentsNotFound().add(buf.getByte(null) == 1); - } - return rep; - } - - @Override - protected boolean doEncode(DocumentReply obj, DocumentSerializer buf) { - BatchDocumentUpdateReply rep = (BatchDocumentUpdateReply)obj; - buf.putLong(null, rep.getHighestModificationTimestamp()); - buf.putInt(null, rep.getDocumentsNotFound().size()); - for (int i = 0; i < rep.getDocumentsNotFound().size(); ++i) { - buf.putByte(null, (byte)(rep.getDocumentsNotFound().get(i) ? 1 : 0)); - } - return true; - } - } - public static class PutDocumentMessageFactory extends DocumentMessageFactory { protected void decodeInto(PutDocumentMessage msg, DocumentDeserializer buf) { msg.setDocumentPut(new DocumentPut(Document.createDocument(buf))); diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java index 6a8c00cc1b1..22f7a491056 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java @@ -252,7 +252,6 @@ public class StoragePolicy extends ExternalSlobrokPolicy { case DocumentProtocol.MESSAGE_STATBUCKET: return ((StatBucketMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_CREATEVISITOR: return ((CreateVisitorMessage)msg).getBuckets().get(0); case DocumentProtocol.MESSAGE_REMOVELOCATION: return ((RemoveLocationMessage)msg).getBucketId(); - case DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE: return ((BatchDocumentUpdateMessage)msg).getBucketId(); default: log.log(LogLevel.ERROR, "Message type '" + msg.getType() + "' not supported."); return null; diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/Messages50TestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/Messages50TestCase.java index 3d02aeee54d..5eca8f49967 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/Messages50TestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/Messages50TestCase.java @@ -30,7 +30,6 @@ public class Messages50TestCase extends MessagesTestBase { protected void registerTests(Map out) { // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support // version 5.0. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now. - out.put(DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE, new testBatchDocumentUpdateMessage()); out.put(DocumentProtocol.MESSAGE_CREATEVISITOR, new testCreateVisitorMessage()); out.put(DocumentProtocol.MESSAGE_DESTROYVISITOR, new testDestroyVisitorMessage()); out.put(DocumentProtocol.MESSAGE_DOCUMENTLIST, new testDocumentListMessage()); @@ -48,7 +47,6 @@ public class Messages50TestCase extends MessagesTestBase { out.put(DocumentProtocol.MESSAGE_STATBUCKET, new testStatBucketMessage()); out.put(DocumentProtocol.MESSAGE_UPDATEDOCUMENT, new testUpdateDocumentMessage()); out.put(DocumentProtocol.MESSAGE_VISITORINFO, new testVisitorInfoMessage()); - out.put(DocumentProtocol.REPLY_BATCHDOCUMENTUPDATE, new testBatchDocumentUpdateReply()); out.put(DocumentProtocol.REPLY_CREATEVISITOR, new testCreateVisitorReply()); out.put(DocumentProtocol.REPLY_DESTROYVISITOR, new testDestroyVisitorReply()); out.put(DocumentProtocol.REPLY_DOCUMENTLIST, new testDocumentListReply()); @@ -722,78 +720,6 @@ public class Messages50TestCase extends MessagesTestBase { } } - public class testBatchDocumentUpdateMessage implements RunnableTest { - - @Override - public void run() { - DocumentType docType = protocol.getDocumentTypeManager().getDocumentType("testdoc"); - BatchDocumentUpdateMessage msg = new BatchDocumentUpdateMessage(1234); - - { - DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("userdoc:footype:1234:foo")); - update.addFieldPathUpdate(new RemoveFieldPathUpdate(docType, "intfield", "testdoc.intfield > 0")); - msg.addUpdate(update); - } - { - DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("orderdoc(32,17):footype:1234:123456789:foo")); - update.addFieldPathUpdate(new RemoveFieldPathUpdate(docType, "intfield", "testdoc.intfield > 0")); - msg.addUpdate(update); - } - - try { - DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("orderdoc:footype:5678:foo")); - update.addFieldPathUpdate(new RemoveFieldPathUpdate(docType, "intfield", "testdoc.intfield > 0")); - msg.addUpdate(update); - fail(); - } catch (Exception e) { - - } - - try { - DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("groupdoc:footype:hable:foo")); - update.addFieldPathUpdate(new RemoveFieldPathUpdate(docType, "intfield", "testdoc.intfield > 0")); - msg.addUpdate(update); - fail(); - } catch (Exception e) { - - } - - assertEquals(2, msg.getUpdates().size()); - - assertEquals(BASE_MESSAGE_LENGTH + 202, serialize("BatchDocumentUpdateMessage", msg)); - - for (Language lang : LANGUAGES) { - msg = (BatchDocumentUpdateMessage)deserialize("BatchDocumentUpdateMessage", DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE, lang); - assertEquals(2, msg.getUpdates().size()); - } - } - } - - public class testBatchDocumentUpdateReply implements RunnableTest { - - @Override - public void run() { - BatchDocumentUpdateReply reply = new BatchDocumentUpdateReply(); - reply.setHighestModificationTimestamp(30); - reply.getDocumentsNotFound().add(false); - reply.getDocumentsNotFound().add(true); - reply.getDocumentsNotFound().add(true); - - assertEquals(20, serialize("BatchDocumentUpdateReply", reply)); - - for (Language lang : LANGUAGES) { - BatchDocumentUpdateReply obj = (BatchDocumentUpdateReply)deserialize("BatchDocumentUpdateReply", DocumentProtocol.REPLY_BATCHDOCUMENTUPDATE, lang); - assertNotNull(obj); - assertEquals(30, obj.getHighestModificationTimestamp()); - assertEquals(3, obj.getDocumentsNotFound().size()); - assertFalse(obj.getDocumentsNotFound().get(0)); - assertTrue(obj.getDocumentsNotFound().get(1)); - assertTrue(obj.getDocumentsNotFound().get(2)); - } - } - } - - public class testQueryResultReply implements RunnableTest { @Override -- cgit v1.2.3