summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-01-12 13:13:40 +0100
committerGitHub <noreply@github.com>2021-01-12 13:13:40 +0100
commitd6c1a483df747f38efa3627eaa9e7fc25a779da3 (patch)
treecd3e9e58e2ea8b48927e096037ac47a273ed5cfc /document
parent6284f410fb6c9e6e086954de479bb600ab301241 (diff)
parent5c932ac437cb8c5c63a7e7b1ccb32853d58b1889 (diff)
Merge pull request #16002 from vespa-engine/balder/move-feed_reject_helper-to-document
Move the feed reject helper to document module.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/CMakeLists.txt1
-rw-r--r--document/src/tests/feed_reject_helper_test.cpp74
-rw-r--r--document/src/vespa/document/util/CMakeLists.txt1
-rw-r--r--document/src/vespa/document/util/feed_reject_helper.cpp52
-rw-r--r--document/src/vespa/document/util/feed_reject_helper.h23
5 files changed, 151 insertions, 0 deletions
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index 46bec1b180b..cd446908b47 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -13,6 +13,7 @@ vespa_add_executable(document_gtest_runner_app TEST
documenttestcase.cpp
documenttypetestcase.cpp
documentupdatetestcase.cpp
+ feed_reject_helper_test.cpp
fieldpathupdatetestcase.cpp
fieldsettest.cpp
fixed_bucket_spaces_test.cpp
diff --git a/document/src/tests/feed_reject_helper_test.cpp b/document/src/tests/feed_reject_helper_test.cpp
new file mode 100644
index 00000000000..8dac86f99eb
--- /dev/null
+++ b/document/src/tests/feed_reject_helper_test.cpp
@@ -0,0 +1,74 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/document/fieldvalue/boolfieldvalue.h>
+#include <vespa/document/fieldvalue/bytefieldvalue.h>
+#include <vespa/document/fieldvalue/shortfieldvalue.h>
+#include <vespa/document/fieldvalue/intfieldvalue.h>
+#include <vespa/document/fieldvalue/longfieldvalue.h>
+#include <vespa/document/fieldvalue/floatfieldvalue.h>
+#include <vespa/document/fieldvalue/doublefieldvalue.h>
+#include <vespa/document/fieldvalue/rawfieldvalue.h>
+#include <vespa/document/fieldvalue/stringfieldvalue.h>
+#include <vespa/document/fieldvalue/predicatefieldvalue.h>
+#include <vespa/document/fieldvalue/referencefieldvalue.h>
+#include <vespa/document/fieldvalue/tensorfieldvalue.h>
+#include <vespa/document/fieldvalue/arrayfieldvalue.h>
+#include <vespa/document/update/removefieldpathupdate.h>
+#include <vespa/document/update/clearvalueupdate.h>
+#include <vespa/document/update/removevalueupdate.h>
+#include <vespa/document/update/arithmeticvalueupdate.h>
+#include <vespa/document/update/addvalueupdate.h>
+#include <vespa/document/update/mapvalueupdate.h>
+#include <vespa/document/update/assignvalueupdate.h>
+
+#include <vespa/document/update/tensor_remove_update.h>
+#include <vespa/document/update/tensor_modify_update.h>
+#include <vespa/document/update/tensor_add_update.h>
+#include <vespa/document/update/tensor_partial_update.h>
+#include <vespa/document/util/feed_reject_helper.h>
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+
+namespace document {
+
+TEST(DocumentRejectTest, requireThatFixedSizeFieldValuesAreDetected) {
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::BoolFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::ByteFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::ShortFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::IntFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::LongFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::FloatFieldValue()));
+ EXPECT_TRUE(FeedRejectHelper::isFixedSizeSingleValue(document::DoubleFieldValue()));
+
+ EXPECT_FALSE(FeedRejectHelper::isFixedSizeSingleValue(document::StringFieldValue()));
+ EXPECT_FALSE(FeedRejectHelper::isFixedSizeSingleValue(document::RawFieldValue()));
+ EXPECT_FALSE(FeedRejectHelper::isFixedSizeSingleValue(document::PredicateFieldValue()));
+ EXPECT_FALSE(FeedRejectHelper::isFixedSizeSingleValue(document::ReferenceFieldValue()));
+
+ document::ArrayDataType intArrayType(*document::DataType::INT);
+ EXPECT_FALSE(FeedRejectHelper::isFixedSizeSingleValue(document::ArrayFieldValue(intArrayType)));
+}
+
+TEST(DocumentRejectTest, requireThatClearRemoveTensorRemoveAndArtithmeticUpdatesIgnoreFeedRejection) {
+ EXPECT_FALSE(FeedRejectHelper::mustReject(ClearValueUpdate()));
+ EXPECT_FALSE(FeedRejectHelper::mustReject(RemoveValueUpdate(StringFieldValue())));
+ EXPECT_FALSE(FeedRejectHelper::mustReject(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5.0)));
+ EXPECT_FALSE(FeedRejectHelper::mustReject(TensorRemoveUpdate(std::make_unique<TensorFieldValue>())));
+}
+
+TEST(DocumentRejectTest, requireThatAddMapTensorModifyAndTensorAddUpdatesWillBeRejected) {
+ EXPECT_TRUE(FeedRejectHelper::mustReject(AddValueUpdate(IntFieldValue())));
+ EXPECT_TRUE(FeedRejectHelper::mustReject(MapValueUpdate(IntFieldValue(), ClearValueUpdate())));
+ EXPECT_TRUE(FeedRejectHelper::mustReject(TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE,
+ std::make_unique<TensorFieldValue>())));
+ EXPECT_TRUE(FeedRejectHelper::mustReject(TensorAddUpdate(std::make_unique<TensorFieldValue>())));
+}
+
+TEST(DocumentRejectTest, requireThatAssignUpdatesWillBeRejectedBasedOnTheirContent) {
+ EXPECT_FALSE(FeedRejectHelper::mustReject(AssignValueUpdate(IntFieldValue())));
+ EXPECT_TRUE(FeedRejectHelper::mustReject(AssignValueUpdate(StringFieldValue())));
+}
+
+}
diff --git a/document/src/vespa/document/util/CMakeLists.txt b/document/src/vespa/document/util/CMakeLists.txt
index 9ad7d4cff06..7b6423a5f34 100644
--- a/document/src/vespa/document/util/CMakeLists.txt
+++ b/document/src/vespa/document/util/CMakeLists.txt
@@ -2,6 +2,7 @@
vespa_add_library(document_util OBJECT
SOURCES
bytebuffer.cpp
+ feed_reject_helper.cpp
printable.cpp
serializableexceptions.cpp
stringutil.cpp
diff --git a/document/src/vespa/document/util/feed_reject_helper.cpp b/document/src/vespa/document/util/feed_reject_helper.cpp
new file mode 100644
index 00000000000..e55b408219c
--- /dev/null
+++ b/document/src/vespa/document/util/feed_reject_helper.cpp
@@ -0,0 +1,52 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "feed_reject_helper.h"
+#include <vespa/document/update/documentupdate.h>
+#include <vespa/document/update/assignvalueupdate.h>
+#include <vespa/document/fieldvalue/boolfieldvalue.h>
+#include <vespa/document/fieldvalue/numericfieldvalue.h>
+
+
+namespace document {
+
+bool
+FeedRejectHelper::isFixedSizeSingleValue(const document::FieldValue & fv) {
+ return fv.inherits(BoolFieldValue::classId) || fv.inherits(NumericFieldValueBase::classId);
+}
+
+bool
+FeedRejectHelper::mustReject(const document::ValueUpdate & valueUpdate) {
+ using namespace document;
+ switch (valueUpdate.getType()) {
+ case ValueUpdate::Add:
+ case ValueUpdate::TensorAddUpdate:
+ case ValueUpdate::TensorModifyUpdate:
+ case ValueUpdate::Map:
+ return true;
+ case ValueUpdate::Assign: {
+ const auto & assign = dynamic_cast<const AssignValueUpdate &>(valueUpdate);
+ if (assign.hasValue()) {
+ if ( ! isFixedSizeSingleValue(assign.getValue())) {
+ return true;
+ }
+ }
+ }
+ default:
+ break;
+ }
+ return false;
+}
+
+bool
+FeedRejectHelper::mustReject(const DocumentUpdate & documentUpdate) {
+ for (const auto & update : documentUpdate.getUpdates()) {
+ for (const auto & valueUpdate : update.getUpdates()) {
+ if (mustReject(*valueUpdate)) {
+ return true;
+ }
+ }
+ }
+ return ! documentUpdate.getFieldPathUpdates().empty();
+}
+
+}
diff --git a/document/src/vespa/document/util/feed_reject_helper.h b/document/src/vespa/document/util/feed_reject_helper.h
new file mode 100644
index 00000000000..a8ba37eb775
--- /dev/null
+++ b/document/src/vespa/document/util/feed_reject_helper.h
@@ -0,0 +1,23 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+namespace document {
+
+class FieldValue;
+class DocumentUpdate;
+class ValueUpdate;
+
+
+/**
+ * Tells wether an operation should be blocked when resourcelimits have been reached.
+ * It looks at the operation type and also the content if it is an 'update' operation.
+ */
+class FeedRejectHelper {
+public:
+ static bool isFixedSizeSingleValue(const FieldValue & fv);
+ static bool mustReject(const ValueUpdate & valueUpdate);
+ static bool mustReject(const DocumentUpdate & documentUpdate);
+};
+
+}