summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-10-07 20:29:40 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-10-07 20:53:05 +0000
commit356172042cbc96375be8d663a945879b9f10dd41 (patch)
treee77fb1af93766b3655df04a55a9fa5dee6ef7971 /document
parent379b3d8c3ce128da5a985ed73fce99326369512c (diff)
- GC unused code.
- vespalib::Lock -> std::mutex
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/bucket/CMakeLists.txt1
-rw-r--r--document/src/vespa/document/bucket/bucketdistribution.cpp115
-rw-r--r--document/src/vespa/document/bucket/bucketdistribution.h136
-rw-r--r--document/src/vespa/document/datatype/positiondatatype.cpp5
-rw-r--r--document/src/vespa/document/datatype/positiondatatype.h2
-rw-r--r--document/src/vespa/document/datatype/urldatatype.cpp10
-rw-r--r--document/src/vespa/document/datatype/urldatatype.h2
-rw-r--r--document/src/vespa/document/select/valuenodes.cpp1
8 files changed, 11 insertions, 261 deletions
diff --git a/document/src/vespa/document/bucket/CMakeLists.txt b/document/src/vespa/document/bucket/CMakeLists.txt
index 7704fe94bd0..fbbfe8b8466 100644
--- a/document/src/vespa/document/bucket/CMakeLists.txt
+++ b/document/src/vespa/document/bucket/CMakeLists.txt
@@ -2,7 +2,6 @@
vespa_add_library(document_bucket OBJECT
SOURCES
bucket.cpp
- bucketdistribution.cpp
bucketid.cpp
bucketidfactory.cpp
bucketidlist.cpp
diff --git a/document/src/vespa/document/bucket/bucketdistribution.cpp b/document/src/vespa/document/bucket/bucketdistribution.cpp
deleted file mode 100644
index 34ce9a9eccf..00000000000
--- a/document/src/vespa/document/bucket/bucketdistribution.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "bucketdistribution.h"
-#include <vespa/log/log.h>
-
-LOG_SETUP(".bucketdistribution");
-
-namespace document {
-
-BucketDistribution::BucketDistribution(uint32_t numColumns, uint32_t numBucketBits) :
- _numColumns(0),
- _numBucketBits(numBucketBits),
- _bucketToColumn(),
- _lock()
-{
- _bucketToColumn.resize(getNumBuckets());
- reset();
- setNumColumns(numColumns);
-}
-
-void
-BucketDistribution::getBucketCount(uint32_t numColumns, uint32_t numBucketBits, std::vector<uint32_t> &ret)
-{
- ret.resize(numColumns);
- uint32_t cnt = getNumBuckets(numBucketBits) / numColumns;
- uint32_t rst = getNumBuckets(numBucketBits) % numColumns;
- for (uint32_t i = 0; i < numColumns; ++i) {
- ret[i] = cnt + (i < rst ? 1 : 0);
- }
-}
-
-void
-BucketDistribution::getBucketMigrateCount(uint32_t numColumns, uint32_t numBucketBits, std::vector<uint32_t> &ret)
-{
- getBucketCount(numColumns++, numBucketBits, ret);
- uint32_t cnt = getNumBuckets(numBucketBits) / numColumns;
- uint32_t rst = getNumBuckets(numBucketBits) % numColumns;
- for (uint32_t i = 0; i < numColumns - 1; ++i) {
- ret[i] -= cnt + (i < rst ? 1 : 0);
- }
-}
-
-void
-BucketDistribution::reset()
-{
- for (std::vector<uint32_t>::iterator it = _bucketToColumn.begin();
- it != _bucketToColumn.end(); ++it) {
- *it = 0;
- }
- _numColumns = 1;
-}
-
-void
-BucketDistribution::addColumn()
-{
- uint32_t newColumns = _numColumns + 1;
- std::vector<uint32_t> migrate;
- getBucketMigrateCount(_numColumns, _numBucketBits, migrate);
- uint32_t numBuckets = getNumBuckets(_numBucketBits);
- for (uint32_t i = 0; i < numBuckets; ++i) {
- uint32_t old = _bucketToColumn[i];
- if (migrate[old] > 0) {
- _bucketToColumn[i] = _numColumns; // move this bucket to the new column
- migrate[old]--;
- }
- }
- _numColumns = newColumns;
-}
-
-void
-BucketDistribution::setNumColumns(uint32_t numColumns)
-{
- vespalib::LockGuard guard(_lock);
- if (numColumns < _numColumns) {
- reset();
- }
- if (numColumns == _numColumns) {
- return;
- }
- for (int i = numColumns - _numColumns; --i >= 0; ) {
- addColumn();
- }
-}
-
-void
-BucketDistribution::setNumBucketBits(uint32_t numBucketBits)
-{
- uint32_t numColumns;
- {
- vespalib::LockGuard guard(_lock);
- if (numBucketBits == _numBucketBits) {
- return;
- }
- _numBucketBits = numBucketBits;
- _bucketToColumn.resize(getNumBuckets(numBucketBits));
- numColumns = _numColumns;
- reset();
- }
- setNumColumns(numColumns);
-}
-
-uint32_t
-BucketDistribution::getColumn(const document::BucketId &bucketId) const
-{
- uint32_t ret = (uint32_t)(bucketId.getId() & (getNumBuckets(_numBucketBits) - 1));
- if (ret >= _bucketToColumn.size()) {
- LOG(error,
- "The bucket distribution map is not in sync with the number of bucket bits. "
- "This should never happen! Distribution is broken!!");
- return 0;
- }
- return _bucketToColumn[ret];
-}
-
-}
diff --git a/document/src/vespa/document/bucket/bucketdistribution.h b/document/src/vespa/document/bucket/bucketdistribution.h
deleted file mode 100644
index c451ed9b9a7..00000000000
--- a/document/src/vespa/document/bucket/bucketdistribution.h
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * \class document::BucketDistribution
- * \ingroup bucket
- *
- * Stable algorithmic hash distribution; this class assigns hash buckets to
- * targets. The number of hash buckets should be large compared to the number
- * of targets. The mapping from hash value to hash bucket is performed outside
- * this class.
- *
- * This is used to determine which search column a bucket should go to.
- */
-#pragma once
-
-#include "bucketid.h"
-#include <vector>
-#include <vespa/vespalib/util/sync.h>
-
-namespace document {
-
-class BucketDistribution {
-public:
- /**
- * Constructs a new bucket distribution object with a given number of
- * columns and buckets.
- *
- * @param numColumns The number of columns to distribute to.
- * @param numBucketBits The number of bits to use for bucket id.
- */
- BucketDistribution(uint32_t numColumns, uint32_t numBucketBits);
-
- /**
- * Returns the number of buckets that the given number of bucket bits will
- * allow.
- *
- * @param numBucketBits The number of bits to use for bucket id.
- * @return The number of buckets allowed.
- */
- static uint32_t getNumBuckets(uint32_t numBucketBits) { return 1 << numBucketBits; }
-
- /**
- * This method returns a list that contains the distributions of the given
- * number of buckets over the given number of columns.
- *
- * @param numColumns The number of columns to distribute to.
- * @param numBucketBits The number of bits to use for bucket id.
- * @param ret List to fill with the bucket distribution.
- */
- static void getBucketCount(uint32_t numColumns, uint32_t numBucketBits,
- std::vector<uint32_t> &ret);
-
- /**
- * This method returns a list similar to getBucketCount(int,int), except
- * that the returned list contains the number of buckets that will have to
- * be migrated from each column if an additional column was added.
- *
- * @param numColumns The original number of columns.
- * @param numBucketBits The number of bits to use for bucket id.
- * @param ret List to fill with the number of buckets to migrate,
- * one value per column.
- */
- static void getBucketMigrateCount(uint32_t numColumns,
- uint32_t numBucketBits, std::vector<uint32_t> &ret);
-
- /**
- * Sets the number of columns to distribute to to 1, and resets the content
- * of the internal bucket-to-column map so that it all buckets point to
- * that single column.
- */
- void reset();
-
- /**
- * Sets the number of columns to use for this document distribution object.
- * This will reset and setup this object from scratch. The original number
- * of buckets is maintained.
- *
- * @param numColumns The new number of columns to distribute to.
- */
- void setNumColumns(uint32_t numColumns);
-
- /**
- * Returns the number of columns to distribute to.
- *
- * @return The number of columns.
- */
- uint32_t getNumColumns() const { return _numColumns; }
-
- /**
- * Sets the number of buckets to use for this document distribution object.
- * This will reset and setup this object from scratch. The original number
- * of columns is maintained.
- *
- * @param numBucketBits The new number of bits to use for bucket id.
- */
- void setNumBucketBits(uint32_t numBucketBits);
-
- /**
- * Returns the number of bits used for bucket identifiers.
- *
- * @return The number of bits.
- */
- uint32_t getNumBucketBits() const { return _numBucketBits; }
-
- /**
- * Returns the number of buckets available using the configured number of
- * bucket bits.
- *
- * @return The number of buckets.
- */
- uint32_t getNumBuckets() const { return getNumBuckets(_numBucketBits); }
-
- /**
- * This method maps the given bucket id to its corresponding column.
- *
- * @param bucketId The bucket whose column to lookup.
- * @return The column to distribute the bucket to.
- */
- uint32_t getColumn(const document::BucketId &bucketId) const;
-
-private:
- /**
- * Adds a single column to this bucket distribution object. This will
- * modify the internal bucket-to-column map so that it takes into account
- * the new column.
- */
- void addColumn();
-
-private:
- uint32_t _numColumns; // The number of columns to distribute to.
- uint32_t _numBucketBits; // The number of bits to use for bucket identification.
- std::vector<uint32_t> _bucketToColumn; // A map from bucket id to column index.
- vespalib::Lock _lock;
-};
-
-} // document
-
diff --git a/document/src/vespa/document/datatype/positiondatatype.cpp b/document/src/vespa/document/datatype/positiondatatype.cpp
index a8e9c81c895..8b323d20fb5 100644
--- a/document/src/vespa/document/datatype/positiondatatype.cpp
+++ b/document/src/vespa/document/datatype/positiondatatype.cpp
@@ -1,17 +1,18 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "positiondatatype.h"
+#include <mutex>
namespace document {
namespace {
const vespalib::string ZCURVE("_zcurve");
+std::mutex _G_lock;
}
StructDataType::UP PositionDataType::_instance;
-vespalib::Lock PositionDataType::_lock;
const vespalib::string PositionDataType::STRUCT_NAME("position");
const vespalib::string PositionDataType::FIELD_X("x");
@@ -30,7 +31,7 @@ const StructDataType &
PositionDataType::getInstance()
{
if ( ! _instance) {
- vespalib::LockGuard guard(_lock);
+ std::lock_guard guard(_G_lock);
if ( ! _instance) {
_instance = createInstance();
}
diff --git a/document/src/vespa/document/datatype/positiondatatype.h b/document/src/vespa/document/datatype/positiondatatype.h
index fa8e44ad847..c7cf1926159 100644
--- a/document/src/vespa/document/datatype/positiondatatype.h
+++ b/document/src/vespa/document/datatype/positiondatatype.h
@@ -2,14 +2,12 @@
#pragma once
#include <vespa/document/datatype/structdatatype.h>
-#include <vespa/vespalib/util/sync.h>
namespace document {
class PositionDataType {
private:
static StructDataType::UP _instance;
- static vespalib::Lock _lock;
PositionDataType();
static StructDataType::UP createInstance();
diff --git a/document/src/vespa/document/datatype/urldatatype.cpp b/document/src/vespa/document/datatype/urldatatype.cpp
index 00ea31408af..bc8c2bee2c7 100644
--- a/document/src/vespa/document/datatype/urldatatype.cpp
+++ b/document/src/vespa/document/datatype/urldatatype.cpp
@@ -1,11 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "urldatatype.h"
+#include <mutex>
namespace document {
+namespace {
+
+std::mutex _G_lock;
+
+}
+
StructDataType::UP UrlDataType::_instance;
-vespalib::Lock UrlDataType::_lock;
const vespalib::string UrlDataType::STRUCT_NAME("url");
const vespalib::string UrlDataType::FIELD_ALL("all");
@@ -34,7 +40,7 @@ const StructDataType &
UrlDataType::getInstance()
{
if ( ! _instance ) {
- vespalib::LockGuard guard(_lock);
+ std::lock_guard guard(_G_lock);
if ( ! _instance ) {
_instance = createInstance();
}
diff --git a/document/src/vespa/document/datatype/urldatatype.h b/document/src/vespa/document/datatype/urldatatype.h
index 902abd940e3..df28b9e56b9 100644
--- a/document/src/vespa/document/datatype/urldatatype.h
+++ b/document/src/vespa/document/datatype/urldatatype.h
@@ -2,14 +2,12 @@
#pragma once
#include <vespa/document/datatype/structdatatype.h>
-#include <vespa/vespalib/util/sync.h>
namespace document {
class UrlDataType {
private:
static StructDataType::UP _instance;
- static vespalib::Lock _lock;
UrlDataType() { /* hide */ }
static StructDataType::UP createInstance();
diff --git a/document/src/vespa/document/select/valuenodes.cpp b/document/src/vespa/document/select/valuenodes.cpp
index 73fc1c6486b..36cb92dfe33 100644
--- a/document/src/vespa/document/select/valuenodes.cpp
+++ b/document/src/vespa/document/select/valuenodes.cpp
@@ -2,7 +2,6 @@
#include "valuenodes.h"
#include "visitor.h"
#include "parser.h"
-#include <vespa/document/bucket/bucketdistribution.h>
#include <vespa/document/base/exceptions.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/document/fieldvalue/fieldvalues.h>