diff options
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/tests/io/fileutil/fileutiltest.cpp | 59 | ||||
-rw-r--r-- | vespalib/src/tests/slaveproc/slaveproc_test.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreebuilder.hpp | 20 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreeinserter.hpp | 17 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreeiterator.hpp | 30 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreeremover.hpp | 12 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreeroot.hpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/btreestore.hpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/btree/noaggrcalc.h | 6 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.cpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.h | 59 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/locale/locale.h | 3 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.cpp | 31 |
15 files changed, 92 insertions, 165 deletions
diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp index 7e15885270c..280edf729b6 100644 --- a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp +++ b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp @@ -21,12 +21,14 @@ int main(int argc, char **argv) { } int retval = 0; +#ifdef __linux__ int err = posix_fadvise(fh, 0, 0, POSIX_FADV_DONTNEED); if (err != 0) { std::error_code ec(errno, std::system_category()); fprintf(stderr, "posix_fadvise failed: %s\n", ec.message().c_str()); retval = 3; } +#endif close(fh); return retval; } diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp index 8345a8dcb99..0aaa84c0585 100644 --- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp +++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp @@ -297,7 +297,11 @@ TEST("require that vespalib::unlink works") TEST_FATAL("Should work on directories."); } catch (IoException& e) { //std::cerr << e.what() << "\n"; +#ifdef __APPLE__ + EXPECT_EQUAL(IoException::NO_PERMISSION, e.getType()); +#else EXPECT_EQUAL(IoException::ILLEGAL_PATH, e.getType()); +#endif } // Works for file { @@ -481,61 +485,6 @@ TEST("require that copy constructor and assignment for vespalib::File works") } } -TEST("require that vespalib::LazyFile works") -{ - // Copy constructor - { - LazyFile file("myfile", File::CREATE, true); - LazyFile file2(file); - EXPECT_EQUAL(file.getFlags(), file2.getFlags()); - EXPECT_EQUAL(file.autoCreateDirectories(), file2.autoCreateDirectories()); - } - // Assignment - { - LazyFile file("myfile", File::CREATE, true); - LazyFile file2("targetfile", File::READONLY); - file = file2; - EXPECT_EQUAL(file.getFlags(), file2.getFlags()); - EXPECT_EQUAL(file.autoCreateDirectories(), file2.autoCreateDirectories()); - } - // Lazily write - { - LazyFile file("myfile", File::CREATE, true); - file.write("foo", 3, 0); - } - // Lazy stat - { - LazyFile file("myfile", File::CREATE, true); - EXPECT_EQUAL(3, file.getFileSize()); - file.close(); - - LazyFile file2("myfile", File::CREATE, true); - FileInfo info = file2.stat(); - EXPECT_EQUAL(3, info._size); - EXPECT_EQUAL(true, info._plainfile); - } - - // Lazy read - { - LazyFile file("myfile", File::CREATE, true); - std::vector<char> buf(10, ' '); - EXPECT_EQUAL(3u, file.read(&buf[0], 10, 0)); - EXPECT_EQUAL(std::string("foo"), std::string(&buf[0], 3)); - } - // Lazy resize - { - LazyFile file("myfile", File::CREATE, true); - file.resize(5); - EXPECT_EQUAL(5, file.getFileSize()); - } - // Lazy get file descriptor - { - LazyFile file("myfile", File::CREATE, true); - int fd = file.getFileDescriptor(); - ASSERT_TRUE(fd != -1); - } -} - TEST("require that vespalib::symlink works") { // Target exists diff --git a/vespalib/src/tests/slaveproc/slaveproc_test.cpp b/vespalib/src/tests/slaveproc/slaveproc_test.cpp index 7a39d4f1c7b..547da991211 100644 --- a/vespalib/src/tests/slaveproc/slaveproc_test.cpp +++ b/vespalib/src/tests/slaveproc/slaveproc_test.cpp @@ -18,7 +18,7 @@ TEST("simple run, ignore output, timeout") { TEST("simple run") { std::string out; - EXPECT_TRUE(SlaveProc::run("echo -n foo", out)); + EXPECT_TRUE(SlaveProc::run("/bin/echo -n foo", out)); EXPECT_EQUAL(out, "foo"); } diff --git a/vespalib/src/vespa/vespalib/btree/btreebuilder.hpp b/vespalib/src/vespa/vespalib/btree/btreebuilder.hpp index fb912499c6c..2cd7d80e06c 100644 --- a/vespalib/src/vespa/vespalib/btree/btreebuilder.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreebuilder.hpp @@ -93,14 +93,14 @@ normalize() _leaf = LeafNodeTypeRefPair(NodeRef(), static_cast<LeafNodeType *>(nullptr)); } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leafNode, _aggrCalc); } assert(_numInserts == leafNode->validSlots()); return; } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leafNode, _aggrCalc); } /* Adjust validLeaves for rightmost nodes */ @@ -115,7 +115,7 @@ normalize() _allocator.mapLeafRef(lcRef)->getLastKey() : _allocator.mapInternalRef(lcRef)->getLastKey(), lcRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*inode, _allocator, _aggrCalc); } } @@ -166,12 +166,12 @@ normalize() _allocator.holdNode(_leaf.ref, leafNode); _numLeafNodes--; _leaf = LeafNodeTypeRefPair(child, leftLeaf); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftLeaf, _aggrCalc); } } else { leafNode->stealSomeFromLeftNode(leftLeaf); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftLeaf, _aggrCalc); Aggregator::recalc(*leafNode, _aggrCalc); } @@ -182,7 +182,7 @@ normalize() pnode->validLeaves(); pnode->incValidLeaves(steal); lpnode->decValidLeaves(steal); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*lpnode, _allocator, _aggrCalc); Aggregator::recalc(*pnode, _allocator, _aggrCalc); } @@ -230,12 +230,12 @@ normalize() _allocator.holdNode(_inodes[level].ref, inode); _numInternalNodes--; _inodes[level] = InternalNodeTypeRefPair(leftInodeRef, leftInode); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftInode, _allocator, _aggrCalc); } } else { inode->stealSomeFromLeftNode(leftInode, _allocator); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftInode, _allocator, _aggrCalc); Aggregator::recalc(*inode, _allocator, _aggrCalc); } @@ -246,7 +246,7 @@ normalize() pnode->validLeaves(); pnode->incValidLeaves(steal); lpnode->decValidLeaves(steal); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*lpnode, _allocator, _aggrCalc); Aggregator::recalc(*pnode, _allocator, _aggrCalc); } @@ -303,7 +303,7 @@ allocNewLeafNode() InternalNodeType *inode; NodeRef child; - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*_leaf.data, _aggrCalc); } LeafNodeTypeRefPair lPair(_allocator.allocLeafNode()); diff --git a/vespalib/src/vespa/vespalib/btree/btreeinserter.hpp b/vespalib/src/vespa/vespalib/btree/btreeinserter.hpp index b24874088a2..e1518da5639 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeinserter.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeinserter.hpp @@ -29,6 +29,7 @@ template <typename KeyT, typename DataT, typename AggrT, typename CompareT, void BTreeInserter<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::rebalanceLeafEntries(LeafNodeType *leafNode, Iterator &itr, AggrCalcT aggrCalc) { + (void)aggrCalc; NodeAllocatorType &allocator(itr.getAllocator()); auto &pathElem = itr.getPath(0); InternalNodeType *parentNode = pathElem.getWNode(); @@ -58,7 +59,7 @@ BTreeInserter<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::rebalanceLeafEn uint32_t given = leftNode->validSlots() - oldLeftValid; parentNode->update(parentIdx, leafNode->getLastKey(), leafRef); parentNode->update(parentIdx - 1, leftNode->getLastKey(), leftRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftNode, allocator, aggrCalc); Aggregator::recalc(*leafNode, allocator, aggrCalc); } @@ -69,7 +70,7 @@ BTreeInserter<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::rebalanceLeafEn rightNode->stealSomeFromLeftNode(leafNode, allocator); parentNode->update(parentIdx, leafNode->getLastKey(), leafRef); parentNode->update(parentIdx + 1, rightNode->getLastKey(), rightRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*rightNode, allocator, aggrCalc); Aggregator::recalc(*leafNode, allocator, aggrCalc); } @@ -110,7 +111,7 @@ insert(BTreeNode::Ref &root, if (lnode->isFull()) { LeafNodeTypeRefPair splitNode = allocator.allocLeafNode(); lnode->splitInsert(splitNode.data, idx, key, data); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { ca = Aggregator::recalc(*lnode, *splitNode.data, aggrCalc); } splitNodeRef = splitNode.ref; // to signal that a split occured @@ -119,7 +120,7 @@ insert(BTreeNode::Ref &root, } else { lnode->insert(idx, key, data); itr.setLeafNodeIdx(idx); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { aggrCalc.add(lnode->getAggregated(), aggrCalc.getVal(data)); ca = lnode->getAggregated(); } @@ -144,7 +145,7 @@ insert(BTreeNode::Ref &root, node->splitInsert(splitNode.data, idx, *splitLastKey, splitNodeRef, allocator); inRightSplit = pe.adjustSplit(inRightSplit, splitNode.data); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { ca = Aggregator::recalc(*node, *splitNode.data, allocator, aggrCalc); } @@ -154,7 +155,7 @@ insert(BTreeNode::Ref &root, node->insert(idx, *splitLastKey, splitNodeRef); pe.adjustSplit(inRightSplit); inRightSplit = false; - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { aggrCalc.add(node->getAggregated(), oldca, ca); ca = node->getAggregated(); } @@ -162,12 +163,12 @@ insert(BTreeNode::Ref &root, splitLastKey = nullptr; } } else { - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { aggrCalc.add(node->getAggregated(), oldca, ca); ca = node->getAggregated(); } } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { oldca = olda; } lastKey = &node->getLastKey(); diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp index 13d41ef61f3..27a50e04f1b 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp @@ -427,7 +427,7 @@ BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: BTreeIteratorBase(const KeyDataType *shortArray, uint32_t arraySize, const NodeAllocatorType &allocator, - const AggrCalcT &aggrCalc) + [[maybe_unused]] const AggrCalcT &aggrCalc) : _leaf(nullptr, 0u), _path(), _pathSize(0), @@ -439,11 +439,9 @@ BTreeIteratorBase(const KeyDataType *shortArray, _compatLeafNode.reset(new LeafNodeTempType(shortArray, arraySize)); _leaf.setNode(_compatLeafNode.get()); _leafRoot = _leaf.getNode(); - typedef BTreeAggregator<KeyT, DataT, AggrT, - INTERNAL_SLOTS, LEAF_SLOTS, AggrCalcT> Aggregator; - if (AggrCalcT::hasAggregated()) { - Aggregator::recalc(const_cast<LeafNodeType &>(*_leaf.getNode()), - aggrCalc); + if constexpr (AggrCalcT::hasAggregated()) { + using Aggregator = BTreeAggregator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, AggrCalcT>; + Aggregator::recalc(const_cast<LeafNodeType &>(*_leaf.getNode()), aggrCalc); } } } @@ -1088,10 +1086,10 @@ template <typename KeyT, typename DataT, typename AggrT, typename CompareT, template <class AggrCalcT> void BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -updateData(const DataType & data, const AggrCalcT &aggrCalc) +updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) { LeafNodeType * lnode = getLeafNode(); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { AggrT oldca(lnode->getAggregated()); typedef BTreeAggregator<KeyT, DataT, AggrT, TraitsT::INTERNAL_SLOTS, @@ -1186,14 +1184,14 @@ template <class AggrCalcT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: insertFirst(const KeyType &key, const DataType &data, - const AggrCalcT &aggrCalc) + [[maybe_unused]] const AggrCalcT &aggrCalc) { assert(_pathSize == 0); assert(_leafRoot == nullptr); NodeAllocatorType &allocator = getAllocator(); LeafNodeTypeRefPair lnode = allocator.allocLeafNode(); lnode.data->insert(0, key, data); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { AggrT a; aggrCalc.add(a, aggrCalc.getVal(data)); lnode.data->getAggregated() = a; @@ -1231,12 +1229,12 @@ template <class AggrCalcT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, - bool inRightSplit, const AggrCalcT &aggrCalc) + bool inRightSplit, [[maybe_unused]] const AggrCalcT &aggrCalc) { - typedef BTreeAggregator<KeyT, DataT, AggrT, - TraitsT::INTERNAL_SLOTS, - TraitsT::LEAF_SLOTS, - AggrCalcT> Aggregator; + using Aggregator = BTreeAggregator<KeyT, DataT, AggrT, + TraitsT::INTERNAL_SLOTS, + TraitsT::LEAF_SLOTS, + AggrCalcT>; NodeAllocatorType &allocator(getAllocator()); @@ -1246,7 +1244,7 @@ addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, allocator.validLeaves(splitNodeRef)); inode->insert(0, allocator.getLastKey(rootRef), rootRef); inode->insert(1, allocator.getLastKey(splitNodeRef), splitNodeRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*inode, allocator, aggrCalc); } _path[_pathSize].setNodeAndIdx(inode, inRightSplit ? 1u : 0u); diff --git a/vespalib/src/vespa/vespalib/btree/btreeremover.hpp b/vespalib/src/vespa/vespalib/btree/btreeremover.hpp index 2281fd99f6d..6a9a7ebcc7e 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeremover.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeremover.hpp @@ -16,7 +16,7 @@ BTreeRemoverBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, AggrCalcT>:: steal(InternalNodeType *pNode, BTreeNode::Ref sNodeRef, NodeType * sNode, uint32_t idx, NodeAllocatorType &allocator, - const AggrCalcT &aggrCalc, + [[maybe_unused]] const AggrCalcT &aggrCalc, Iterator &itr, uint32_t level) { @@ -65,7 +65,7 @@ steal(InternalNodeType *pNode, uint32_t stolen = oldLeftValid - leftVictim->validSlots(); pNode->update(idx, sNode->getLastKey(), sNodeRef); pNode->update(idx - 1, leftVictim->getLastKey(), leftVictimRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*leftVictim, allocator, aggrCalc); } itr.adjustSteal(level, false, stolen); @@ -79,11 +79,11 @@ steal(InternalNodeType *pNode, sNode->stealSomeFromRightNode(rightVictim, allocator); pNode->update(idx, sNode->getLastKey(), sNodeRef); pNode->update(idx + 1, rightVictim->getLastKey(), rightVictimRef); - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*rightVictim, allocator, aggrCalc); } } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*sNode, allocator, aggrCalc); } } @@ -118,7 +118,7 @@ remove(BTreeNode::Ref &root, } else { lnode->remove(idx); } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { ca = lnode->getAggregated(); } bool steppedBack = idx >= lnode->validSlots(); @@ -160,7 +160,7 @@ remove(BTreeNode::Ref &root, itr, level); } } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { if (aggrCalc.remove(node->getAggregated(), oldca, ca)) { Aggregator::recalc(*node, allocator, aggrCalc); } diff --git a/vespalib/src/vespa/vespalib/btree/btreeroot.hpp b/vespalib/src/vespa/vespalib/btree/btreeroot.hpp index 22703f2dfd2..3893e0e0124 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeroot.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeroot.hpp @@ -63,7 +63,7 @@ isValid(BTreeNode::Ref node, return false; } } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { AggrT aggregated = Aggregator::aggregate(*lnode, aggrCalc); if (aggregated != lnode->getAggregated()) { return false; @@ -113,7 +113,7 @@ isValid(BTreeNode::Ref node, if (lChildren < inode->validSlots() && iChildren < inode->validSlots()) { return false; } - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { AggrT aggregated = Aggregator::aggregate(*inode, allocator, aggrCalc); if (aggregated != inode->getAggregated()) { return false; diff --git a/vespalib/src/vespa/vespalib/btree/btreestore.hpp b/vespalib/src/vespa/vespalib/btree/btreestore.hpp index 614546903dc..ec3be588de4 100644 --- a/vespalib/src/vespa/vespalib/btree/btreestore.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreestore.hpp @@ -176,7 +176,7 @@ makeTree(EntryRef &ref, } typedef BTreeAggregator<KeyT, DataT, AggrT, TraitsT::INTERNAL_SLOTS, TraitsT::LEAF_SLOTS, AggrCalcT> Aggregator; - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*lNode, _aggrCalc); } lNode->freeze(); @@ -304,7 +304,7 @@ insert(EntryRef &ref, assert(idx == clusterSize + 1); typedef BTreeAggregator<KeyT, DataT, AggrT, TraitsT::INTERNAL_SLOTS, TraitsT::LEAF_SLOTS, AggrCalcT> Aggregator; - if (AggrCalcT::hasAggregated()) { + if constexpr (AggrCalcT::hasAggregated()) { Aggregator::recalc(*lNode, _aggrCalc); } lNode->freeze(); diff --git a/vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h b/vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h index b33422ec3e3..66e23127c5a 100644 --- a/vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h +++ b/vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h @@ -9,8 +9,8 @@ namespace search::btree { class MinMaxAggrCalc { public: - MinMaxAggrCalc() { } - static bool hasAggregated() { return true; } + constexpr MinMaxAggrCalc() = default; + constexpr static bool hasAggregated() { return true; } static int32_t getVal(int32_t val) { return val; } static void add(MinMaxAggregated &a, int32_t val) { a.add(val); } static void add(MinMaxAggregated &a, const MinMaxAggregated &ca) { a.add(ca); } diff --git a/vespalib/src/vespa/vespalib/btree/noaggrcalc.h b/vespalib/src/vespa/vespalib/btree/noaggrcalc.h index e77e8bc204a..079abc57224 100644 --- a/vespalib/src/vespa/vespalib/btree/noaggrcalc.h +++ b/vespalib/src/vespa/vespalib/btree/noaggrcalc.h @@ -9,11 +9,9 @@ namespace search::btree { class NoAggrCalc { public: - NoAggrCalc() - { - } + constexpr NoAggrCalc() = default; - static bool + constexpr static bool hasAggregated() { return false; diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp index 3f54b83bee6..5840b621a6c 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.cpp +++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp @@ -180,10 +180,13 @@ File::open(int flags, bool autoCreateDirectories) { } int openflags = ((flags & File::READONLY) != 0 ? O_RDONLY : O_RDWR) | ((flags & File::CREATE) != 0 ? O_CREAT : 0) +#ifdef __linux__ | ((flags & File::DIRECTIO) != 0 ? O_DIRECT : 0) +#endif | ((flags & File::TRUNC) != 0 ? O_TRUNC: 0); int fd = openAndCreateDirsIfMissing(_filename, openflags, autoCreateDirectories); +#ifdef __linux__ if (fd < 0 && ((flags & File::DIRECTIO) != 0)) { openflags = (openflags ^ O_DIRECT); flags = (flags ^ DIRECTIO); @@ -193,6 +196,7 @@ File::open(int flags, bool autoCreateDirectories) { fd = openAndCreateDirsIfMissing(_filename, openflags, autoCreateDirectories); } +#endif if (fd < 0) { asciistream ost; ost << "open(" << _filename << ", 0x" diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h index 1507513dbbc..59994819600 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.h +++ b/vespalib/src/vespa/vespalib/io/fileutil.h @@ -209,65 +209,6 @@ public: }; /** - * @brief A File instance that automatically opens once needed. - */ -class LazyFile : public File { - int _flags; - bool _autoCreateDirectories; - -public: - typedef std::unique_ptr<LazyFile> UP; - - LazyFile(vespalib::stringref filename, int flags, - bool autoCreateDirs = false) - : File(filename), - _flags(flags), - _autoCreateDirectories(autoCreateDirs) {} - - LazyFile(LazyFile& other) - : File(other), - _flags(other._flags), - _autoCreateDirectories(other._autoCreateDirectories) {} - - LazyFile& operator=(LazyFile& other) { - File::operator=(other); - _flags = other._flags; - _autoCreateDirectories = other._autoCreateDirectories; - return *this; - } - - int getFlags() const { return _flags; } - void setFlags(int flags) { _flags = flags; } - void setAutoCreateDirectories(bool autoCreate) - { _autoCreateDirectories = autoCreate; } - bool autoCreateDirectories() const { return _autoCreateDirectories; } - - int getFileDescriptor() const override { - if (!isOpen()) { - const_cast<LazyFile&>(*this).open(_flags, _autoCreateDirectories); - } - return File::getFileDescriptor(); - } - - void resize(off_t size) override { - if (!isOpen()) { open(_flags, _autoCreateDirectories); } - File::resize(size); - } - - off_t write(const void *buf, size_t bufsize, off_t offset) override { - if (!isOpen()) { open(_flags, _autoCreateDirectories); } - return File::write(buf, bufsize, offset); - } - - size_t read(void *buf, size_t bufsize, off_t offset) const override { - if (!isOpen()) { - const_cast<LazyFile&>(*this).open(_flags, _autoCreateDirectories); - } - return File::read(buf, bufsize, offset); - } -}; - -/** * Get the current working directory. * * @throw IoException On failure. diff --git a/vespalib/src/vespa/vespalib/locale/locale.h b/vespalib/src/vespa/vespalib/locale/locale.h index ee2bbe54af3..ed3ca560630 100644 --- a/vespalib/src/vespa/vespalib/locale/locale.h +++ b/vespalib/src/vespa/vespalib/locale/locale.h @@ -3,6 +3,9 @@ #pragma once #include <clocale> +#ifndef __linux__ +#include <xlocale.h> +#endif namespace vespalib::locale { diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index 46cf4806dfc..61a295c6dc3 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -52,3 +52,34 @@ Timer::waitAtLeast(duration dur, bool busyWait) { } } + +namespace std::chrono { + +/* + * This is a hack to avoid the slow clock computations on RHEL7/CentOS 7 due to using systemcalls. + * This brings cost down from 550-560ns to 18-19ns on a Intel Haswell 2680 cpu. + * We are providing the symbols here so they will take precedence over the ones in the standard library. + * We rely on the linker do handle correct symbol resolution. + * TODO: Once we are off the ancient platforms like Centos 7/ Rhel 7 we can drop this workaround. +*/ + +inline namespace _V2 { + +system_clock::time_point +system_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +steady_clock::time_point +steady_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +} +} |