summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-01-11 22:25:03 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-01-11 22:25:03 +0000
commit3aa01ec8ce4b509569a4e6c8f64858038b2ca5d4 (patch)
tree6fbf6080266e5d6774317ba0f453c4a4fb1fc917 /searchcore
parent6d5b7bb9cff88d5030a606082b703a2c706e0747 (diff)
Move the feed reject helper to document module.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp48
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt1
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.cpp75
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.h30
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp32
5 files changed, 32 insertions, 154 deletions
diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
index d466e5a00d2..7d75d1a6327 100644
--- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
@@ -6,16 +6,7 @@
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/document/update/clearvalueupdate.h>
-#include <vespa/document/update/removevalueupdate.h>
-#include <vespa/document/update/addvalueupdate.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/update/arithmeticvalueupdate.h>
-#include <vespa/document/update/mapvalueupdate.h>
#include <vespa/document/update/removefieldpathupdate.h>
-#include <vespa/document/fieldvalue/referencefieldvalue.h>
#include <vespa/eval/eval/simple_value.h>
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/eval/eval/value.h>
@@ -29,7 +20,7 @@
#include <vespa/searchcore/proton/feedoperation/updateoperation.h>
#include <vespa/searchcore/proton/persistenceengine/i_resource_write_filter.h>
#include <vespa/searchcore/proton/server/configstore.h>
-#include <vespa/searchcore/proton/server/feed_reject_helper.h>
+#include <vespa/document/util/feed_reject_helper.h>
#include <vespa/searchcore/proton/server/ddbstate.h>
#include <vespa/searchcore/proton/server/executorthreadingservice.h>
#include <vespa/searchcore/proton/server/feedhandler.h>
@@ -819,45 +810,8 @@ TEST_F("require that put with different document type repo is ok", FeedHandlerFi
EXPECT_EQUAL(1, f.tls_writer.store_count);
}
-TEST("require that fixed size field values are detected") {
- 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)));
-}
-
using namespace document;
-TEST("require that clear, remove, tensor_remove and artithmetic updates ignore feed rejection") {
- 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("require that add, map, tensor_modify and tensor_add updates will be rejected") {
- 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("require that assign updates will be rejected based on their content") {
- EXPECT_FALSE(FeedRejectHelper::mustReject(AssignValueUpdate(IntFieldValue())));
- EXPECT_TRUE(FeedRejectHelper::mustReject(AssignValueUpdate(StringFieldValue())));
-}
-
TEST_F("require that update with a fieldpath update will be rejected", SchemaContext) {
const DocumentType *docType = f.getRepo()->getDocumentType(f.getDocType().getName());
auto docUpdate = std::make_unique<DocumentUpdate>(*f.getRepo(), *docType, DocumentId("id:ns:" + docType->getName() + "::1"));
diff --git a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
index 85e01f9a8ed..73b7404ce31 100644
--- a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
+++ b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
@@ -46,7 +46,6 @@ vespa_add_library(searchcore_server STATIC
feedhandler.cpp
feedstate.cpp
feedstates.cpp
- feed_reject_helper.cpp
fileconfigmanager.cpp
flushhandlerproxy.cpp
forcecommitcontext.cpp
diff --git a/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.cpp b/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.cpp
deleted file mode 100644
index 43cc975acc2..00000000000
--- a/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// 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/searchcore/proton/feedoperation/operations.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>
-
-using namespace document;
-
-namespace proton {
-
-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();
-}
-
-bool
-FeedRejectHelper::mustReject(const UpdateOperation & updateOperation) {
- using namespace document;
- if (updateOperation.getUpdate()) {
- return mustReject(*updateOperation.getUpdate());
- }
- return false;
-}
-
-bool
-FeedRejectHelper::isRejectableFeedOperation(const FeedOperation & op)
-{
- FeedOperation::Type type = op.getType();
- if (type == FeedOperation::PUT) {
- return true;
- } else if (type == FeedOperation::UPDATE_42 || type == FeedOperation::UPDATE) {
- return mustReject(dynamic_cast<const UpdateOperation &>(op));
- }
- return false;
-}
-
-}
diff --git a/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.h b/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.h
deleted file mode 100644
index 00a8b3d77ad..00000000000
--- a/searchcore/src/vespa/searchcore/proton/server/feed_reject_helper.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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;
-}
-
-namespace proton {
-
-class FeedOperation;
-class UpdateOperation;
-
-/**
- * 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 isRejectableFeedOperation(const FeedOperation & op);
- // Public only for testing
- static bool isFixedSizeSingleValue(const document::FieldValue & fv);
- static bool mustReject(const document::ValueUpdate & valueUpdate);
- static bool mustReject(const document::DocumentUpdate & documentUpdate);
- static bool mustReject(const UpdateOperation & updateOperation);
-};
-
-}
diff --git a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
index 132fdf56b90..7f9661f9c06 100644
--- a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
@@ -6,7 +6,7 @@
#include "i_feed_handler_owner.h"
#include "ifeedview.h"
#include "configstore.h"
-#include "feed_reject_helper.h"
+#include <vespa/document/util/feed_reject_helper.h>
#include <vespa/document/base/exceptions.h>
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/repo/documenttyperepo.h>
@@ -612,6 +612,36 @@ notifyFeedOperationRejected(FeedToken & token, const FeedOperation &op,
}
}
+/**
+ * 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 isRejectableFeedOperation(const FeedOperation & op);
+ static bool mustReject(const UpdateOperation & updateOperation);
+};
+
+bool
+FeedRejectHelper::mustReject(const UpdateOperation & updateOperation) {
+ if (updateOperation.getUpdate()) {
+ return document::FeedRejectHelper::mustReject(*updateOperation.getUpdate());
+ }
+ return false;
+}
+
+bool
+FeedRejectHelper::isRejectableFeedOperation(const FeedOperation & op)
+{
+ FeedOperation::Type type = op.getType();
+ if (type == FeedOperation::PUT) {
+ return true;
+ } else if (type == FeedOperation::UPDATE_42 || type == FeedOperation::UPDATE) {
+ return mustReject(dynamic_cast<const UpdateOperation &>(op));
+ }
+ return false;
+}
+
}
bool