summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahoo-inc.com>2017-05-11 13:23:34 +0000
committerTor Egge <Tor.Egge@yahoo-inc.com>2017-05-11 13:23:34 +0000
commita5343c88022a9fd5b60c6273f44cf1bc4e1f56a9 (patch)
treefa6d905c40bcc08787c80bf82192e7f04239161b /searchcore
parent43232cffe1fccbdda46f57e93dbe238d375f3108 (diff)
Prepare for adding extra flush targets (for shrinking lid space) to
attribute manager.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp57
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h18
2 files changed, 57 insertions, 18 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp
index 2fa567e0c6d..03ec1836655 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp
+++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp
@@ -91,6 +91,21 @@ AttributeManager::AttributeWrap::normalAttribute(const AttributeVectorSP &a)
return AttributeWrap(a, false);
}
+AttributeManager::FlushableWrap::FlushableWrap()
+ : _flusher(),
+ _shrinker()
+{
+}
+
+AttributeManager::FlushableWrap::FlushableWrap(FlushableAttributeSP flusher, ShrinkerSP shrinker)
+ : _flusher(std::move(flusher)),
+ _shrinker(std::move(shrinker))
+{
+}
+
+AttributeManager::FlushableWrap::~FlushableWrap()
+{
+}
AttributeVector::SP
AttributeManager::internalAddAttribute(const AttributeSpec &spec,
@@ -114,12 +129,15 @@ AttributeManager::addAttribute(const AttributeWrap &attribute)
assert(attribute.getAttribute()->getInterlock() == _interlock);
if ( ! attribute.isExtra() ) {
// Flushing of extra attributes is handled elsewhere
- _flushables[attribute.getAttribute()->getName()] = FlushableAttribute::SP
- (new FlushableAttribute(attribute.getAttribute(), _diskLayout->createAttributeDir(attribute.getAttribute()->getName()),
- _tuneFileAttributes,
- _fileHeaderContext,
- _attributeFieldWriter,
- _hwInfo));
+ auto flusher = std::make_shared<FlushableAttribute>
+ (attribute.getAttribute(),
+ _diskLayout->createAttributeDir(attribute.getAttribute()->getName()),
+ _tuneFileAttributes,
+ _fileHeaderContext,
+ _attributeFieldWriter,
+ _hwInfo);
+ auto shrinker = std::shared_ptr<ShrinkLidSpaceFlushTarget>();
+ _flushables[attribute.getAttribute()->getName()] = FlushableWrap(flusher, shrinker);
_writableAttributes.push_back(attribute.getAttribute().get());
}
}
@@ -133,11 +151,11 @@ AttributeManager::findAttribute(const vespalib::string &name) const
: AttributeVector::SP();
}
-FlushableAttribute::SP
+const AttributeManager::FlushableWrap *
AttributeManager::findFlushable(const vespalib::string &name) const
{
FlushableMap::const_iterator itr = _flushables.find(name);
- return (itr != _flushables.end()) ? itr->second : FlushableAttribute::SP();
+ return (itr != _flushables.end()) ? &itr->second : nullptr;
}
void
@@ -296,7 +314,7 @@ AttributeManager::flushAll(SerialNum currentSerial)
{
for (const auto &kv : _flushables) {
vespalib::Executor::Task::UP task;
- task = kv.second->initFlush(currentSerial);
+ task = kv.second.getFlusher()->initFlush(currentSerial);
if (task.get() != NULL) {
task->run();
}
@@ -306,7 +324,11 @@ AttributeManager::flushAll(SerialNum currentSerial)
FlushableAttribute::SP
AttributeManager::getFlushable(const vespalib::string &name)
{
- return findFlushable(name);
+ auto wrap = findFlushable(name);
+ if (wrap != nullptr) {
+ return wrap->getFlusher();
+ }
+ return FlushableAttribute::SP();
}
size_t
@@ -429,7 +451,7 @@ AttributeManager::getFlushTargets() const
std::vector<IFlushTarget::SP> list;
list.reserve(_flushables.size());
for (const auto &kv : _flushables) {
- list.push_back(kv.second);
+ list.push_back(kv.second.getFlusher());
}
return list;
}
@@ -437,9 +459,12 @@ AttributeManager::getFlushTargets() const
search::SerialNum
AttributeManager::getFlushedSerialNum(const vespalib::string &name) const
{
- FlushableAttribute::SP flushable = findFlushable(name);
- if (flushable.get() != nullptr) {
- return flushable->getFlushedSerialNum();
+ auto wrap = findFlushable(name);
+ if (wrap != nullptr) {
+ const auto &flusher = wrap->getFlusher();
+ if (flusher) {
+ return flusher->getFlushedSerialNum();
+ }
}
return 0;
}
@@ -449,7 +474,7 @@ AttributeManager::getOldestFlushedSerialNumber() const
{
SerialNum num = -1;
for (const auto &kv : _flushables) {
- num = std::min(num, kv.second->getFlushedSerialNum());
+ num = std::min(num, kv.second.getFlusher()->getFlushedSerialNum());
}
return num;
}
@@ -459,7 +484,7 @@ AttributeManager::getNewestFlushedSerialNumber() const
{
SerialNum num = 0;
for (const auto &kv : _flushables) {
- num = std::max(num, kv.second->getFlushedSerialNum());
+ num = std::max(num, kv.second.getFlusher()->getFlushedSerialNum());
}
return num;
}
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h
index 7bfaf337420..cb76a5a4aef 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h
+++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h
@@ -35,6 +35,7 @@ namespace proton
class AttributeDiskLayout;
class FlushableAttribute;
+class ShrinkLidSpaceFlushTarget;
/**
* Specialized attribute manager for proton.
@@ -46,6 +47,7 @@ private:
typedef search::SerialNum SerialNum;
typedef AttributeCollectionSpec Spec;
using FlushableAttributeSP = std::shared_ptr<FlushableAttribute>;
+ using ShrinkerSP = std::shared_ptr<ShrinkLidSpaceFlushTarget>;
using IFlushTargetSP = std::shared_ptr<searchcorespi::IFlushTarget>;
using AttributeVectorSP = std::shared_ptr<search::AttributeVector>;
@@ -64,8 +66,20 @@ private:
const AttributeVectorSP getAttribute() const { return _attr; }
};
+ class FlushableWrap
+ {
+ FlushableAttributeSP _flusher;
+ ShrinkerSP _shrinker;
+ public:
+ FlushableWrap();
+ FlushableWrap(FlushableAttributeSP flusher, ShrinkerSP shrinker);
+ ~FlushableWrap();
+ const FlushableAttributeSP &getFlusher() const { return _flusher; }
+ const ShrinkerSP &getShrinker() const { return _shrinker; }
+ };
+
typedef vespalib::hash_map<vespalib::string, AttributeWrap> AttributeMap;
- typedef vespalib::hash_map<vespalib::string, FlushableAttributeSP> FlushableMap;
+ typedef vespalib::hash_map<vespalib::string, FlushableWrap> FlushableMap;
AttributeMap _attributes;
FlushableMap _flushables;
@@ -88,7 +102,7 @@ private:
AttributeVectorSP findAttribute(const vespalib::string &name) const;
- FlushableAttributeSP findFlushable(const vespalib::string &name) const;
+ const FlushableWrap *findFlushable(const vespalib::string &name) const;
void transferExistingAttributes(const AttributeManager &currMgr,
const Spec &newSpec,