You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/08/24 09:06:18 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request #877: MINIFICPP-1339 - Disk full

adamdebreceni opened a new pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877


   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475565395



##########
File path: extensions/rocksdb-repos/RocksDatabase.h
##########
@@ -0,0 +1,98 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+
+#include "utils/OptionalUtils.h"
+#include "rocksdb/db.h"
+#include "rocksdb/options.h"
+#include "rocksdb/slice.h"
+#include "rocksdb/utilities/checkpoint.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+class RocksDatabase;
+
+// Not thread safe
+class OpenRocksDB {
+  friend class RocksDatabase;
+
+  OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl);
+
+ public:
+  rocksdb::Status Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value);
+
+  rocksdb::Status Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value);
+
+  std::vector<rocksdb::Status> MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values);
+
+  rocksdb::Status Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates);
+
+  rocksdb::Status Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key);
+
+  rocksdb::Status Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value);
+
+  bool GetProperty(const rocksdb::Slice& property, std::string* value);
+
+  rocksdb::Iterator* NewIterator(const rocksdb::ReadOptions& options);

Review comment:
       done

##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -71,7 +75,7 @@ void FlowFileRepository::flush() {
     batch.Delete(keys[i]);
   }
 
-  auto operation = [this, &batch]() { return db_->Write(rocksdb::WriteOptions(), &batch); };
+  auto operation = [this, &batch, &opendb]() { return opendb->Write(rocksdb::WriteOptions(), &batch); };

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475634470



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -134,14 +142,18 @@ void FlowFileRepository::prune_stored_flowfiles() {
     if (status.ok()) {

Review comment:
       made it possible to create a `RocksDatabase` in a `ReadOnly` mode, so `::open` acts accordingly, this cleared up the three different DB variables




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476239186



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,138 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }
+  return results;
+}
+
+rocksdb::Status OpenRocksDB::Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates) {
+  rocksdb::Status result = impl_->Write(options, updates);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key) {
+  rocksdb::Status result = impl_->Delete(options, key);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Merge(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+bool OpenRocksDB::GetProperty(const rocksdb::Slice& property, std::string* value) {
+  return impl_->GetProperty(property, value);
+}
+
+std::unique_ptr<rocksdb::Iterator> OpenRocksDB::NewIterator(const rocksdb::ReadOptions& options) {
+  return std::unique_ptr<rocksdb::Iterator>{impl_->NewIterator(options)};
+}
+
+rocksdb::Status OpenRocksDB::NewCheckpoint(rocksdb::Checkpoint **checkpoint) {
+  return rocksdb::Checkpoint::Create(impl_.get(), checkpoint);
+}
+
+rocksdb::Status OpenRocksDB::FlushWAL(bool sync) {
+  rocksdb::Status result = impl_->FlushWAL(sync);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::DB* OpenRocksDB::get() {
+  return impl_.get();
+}
+
+RocksDatabase::RocksDatabase(const rocksdb::Options& options, const std::string& name, Mode mode) : open_options_(options), db_name_(name), mode_(mode) {}
+
+void RocksDatabase::invalidate() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  // discard our own instance
+  impl_.reset();
+}
+
+utils::optional<OpenRocksDB> RocksDatabase::open() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  if (!impl_) {
+    // database is not opened yet
+    rocksdb::DB* db_instance = nullptr;
+    rocksdb::Status result;
+    if (mode_ == Mode::ReadWrite) {

Review comment:
       🤔 I think we should enable that error, although not in this PR




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476276313



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }

Review comment:
       I think 
   ```c++
   auto is_nospace = [](auto status){ return status == rocksdb::Status::NoSpace(); };
   if (std::ranges::any_of(results, is_nospace)) { ... }
   ```
   is OK, and it is reality in C++20, so it will be available in minificpp in about ten years. :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475699525



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,138 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }
+  return results;
+}
+
+rocksdb::Status OpenRocksDB::Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates) {
+  rocksdb::Status result = impl_->Write(options, updates);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key) {
+  rocksdb::Status result = impl_->Delete(options, key);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Merge(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+bool OpenRocksDB::GetProperty(const rocksdb::Slice& property, std::string* value) {
+  return impl_->GetProperty(property, value);
+}
+
+std::unique_ptr<rocksdb::Iterator> OpenRocksDB::NewIterator(const rocksdb::ReadOptions& options) {
+  return std::unique_ptr<rocksdb::Iterator>{impl_->NewIterator(options)};
+}
+
+rocksdb::Status OpenRocksDB::NewCheckpoint(rocksdb::Checkpoint **checkpoint) {
+  return rocksdb::Checkpoint::Create(impl_.get(), checkpoint);
+}
+
+rocksdb::Status OpenRocksDB::FlushWAL(bool sync) {
+  rocksdb::Status result = impl_->FlushWAL(sync);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::DB* OpenRocksDB::get() {
+  return impl_.get();
+}
+
+RocksDatabase::RocksDatabase(const rocksdb::Options& options, const std::string& name, Mode mode) : open_options_(options), db_name_(name), mode_(mode) {}
+
+void RocksDatabase::invalidate() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  // discard our own instance
+  impl_.reset();
+}
+
+utils::optional<OpenRocksDB> RocksDatabase::open() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  if (!impl_) {
+    // database is not opened yet
+    rocksdb::DB* db_instance = nullptr;
+    rocksdb::Status result;
+    if (mode_ == Mode::ReadWrite) {

Review comment:
       I would recommend promoting such a warning to an error at the project level by adding `-Werror=switch-enum` to minifi.
   
   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wswitch-default
   https://clang.llvm.org/docs/DiagnosticsReference.html#wswitch-enum




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475663017



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#note-392 Last sentence of "Exceptions":
   > Note that using a reference member is almost always wrong.
   Sadly there is no explanation and I couldn't find one elsewhere either.
   
   I was not aware of the convention either, that taking a reference indicates not storing it. Do you have any resources explaining it? My disk space watchdog PR is affected because it takes ctor args by reference just to store them in a `gsl::not_null<T*>` member.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475671668



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,138 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }
+  return results;
+}
+
+rocksdb::Status OpenRocksDB::Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates) {
+  rocksdb::Status result = impl_->Write(options, updates);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key) {
+  rocksdb::Status result = impl_->Delete(options, key);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Merge(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+bool OpenRocksDB::GetProperty(const rocksdb::Slice& property, std::string* value) {
+  return impl_->GetProperty(property, value);
+}
+
+std::unique_ptr<rocksdb::Iterator> OpenRocksDB::NewIterator(const rocksdb::ReadOptions& options) {
+  return std::unique_ptr<rocksdb::Iterator>{impl_->NewIterator(options)};
+}
+
+rocksdb::Status OpenRocksDB::NewCheckpoint(rocksdb::Checkpoint **checkpoint) {
+  return rocksdb::Checkpoint::Create(impl_.get(), checkpoint);
+}
+
+rocksdb::Status OpenRocksDB::FlushWAL(bool sync) {
+  rocksdb::Status result = impl_->FlushWAL(sync);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::DB* OpenRocksDB::get() {
+  return impl_.get();
+}
+
+RocksDatabase::RocksDatabase(const rocksdb::Options& options, const std::string& name, Mode mode) : open_options_(options), db_name_(name), mode_(mode) {}
+
+void RocksDatabase::invalidate() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  // discard our own instance
+  impl_.reset();
+}
+
+utils::optional<OpenRocksDB> RocksDatabase::open() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  if (!impl_) {
+    // database is not opened yet
+    rocksdb::DB* db_instance = nullptr;
+    rocksdb::Status result;
+    if (mode_ == Mode::ReadWrite) {

Review comment:
       could we promote such a warning to an error at the file/function/block level?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476276313



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }

Review comment:
       I think 
   ```c++
   auto is_nospace = [](auto status){ return status == rocksdb::Status::NoSpace(); };
   if (std::ranges::any_of(results, is_nospace) { ... }
   ```
   is OK, and it is reality in C++20, so it will be available in minificpp in about ten years. :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475550882



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       I was under the impression that taking a reference indicates that we are not planning on storing it, is this not a generally recognized convention?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476475343



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -194,22 +201,27 @@ bool FlowFileRepository::ExecuteWithRetry(std::function<rocksdb::Status()> opera
  * Returns True if there is data to interrogate.
  * @return true if our db has data stored.
  */
-bool FlowFileRepository::need_checkpoint(){
-  std::unique_ptr<rocksdb::Iterator> it = std::unique_ptr<rocksdb::Iterator>(db_->NewIterator(rocksdb::ReadOptions()));
+bool FlowFileRepository::need_checkpoint(minifi::internal::OpenRocksDB& opendb){
+  auto it = opendb.NewIterator(rocksdb::ReadOptions());
   for (it->SeekToFirst(); it->Valid(); it->Next()) {

Review comment:
       great question, this whole checkpointing needs to be revisited because it is not really fault tolerant, e.g. it starts reading from the live db if it couldn't open the checkpoint, there is no retry with the checkpoint etc., for now I'll replace this magical loop 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475689892



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       I couldn't find a convincing argument either, only a gut feeling that having `U f(T& t)` and `U g(T* t)`, after calling `g` I'm more reluctant to discard the `t` I provided than after calling `f`, I feel like if I write `f` I'm signaling that I only need the object for the duration of the function




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475693218



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }

Review comment:
       Could the db be invalidated on the first bad result only?
   
   ```suggestion
       if (std::any_of(results.begin(), results.end(), [](const rocksdb::Status& status){ return status == rocksdb::Status::NoSpace();})
         db_->invalidate();
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475661186



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -134,14 +142,18 @@ void FlowFileRepository::prune_stored_flowfiles() {
     if (status.ok()) {

Review comment:
       very nice, thank you!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r477068493



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -91,14 +95,18 @@ void FlowFileRepository::flush() {
 }
 
 void FlowFileRepository::printStats() {
+  auto opendb = db_->open();
+  if (!opendb) {
+    return;

Review comment:
       logging error on failed `open`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475699525



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,138 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }
+  return results;
+}
+
+rocksdb::Status OpenRocksDB::Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates) {
+  rocksdb::Status result = impl_->Write(options, updates);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key) {
+  rocksdb::Status result = impl_->Delete(options, key);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Merge(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+bool OpenRocksDB::GetProperty(const rocksdb::Slice& property, std::string* value) {
+  return impl_->GetProperty(property, value);
+}
+
+std::unique_ptr<rocksdb::Iterator> OpenRocksDB::NewIterator(const rocksdb::ReadOptions& options) {
+  return std::unique_ptr<rocksdb::Iterator>{impl_->NewIterator(options)};
+}
+
+rocksdb::Status OpenRocksDB::NewCheckpoint(rocksdb::Checkpoint **checkpoint) {
+  return rocksdb::Checkpoint::Create(impl_.get(), checkpoint);
+}
+
+rocksdb::Status OpenRocksDB::FlushWAL(bool sync) {
+  rocksdb::Status result = impl_->FlushWAL(sync);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::DB* OpenRocksDB::get() {
+  return impl_.get();
+}
+
+RocksDatabase::RocksDatabase(const rocksdb::Options& options, const std::string& name, Mode mode) : open_options_(options), db_name_(name), mode_(mode) {}
+
+void RocksDatabase::invalidate() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  // discard our own instance
+  impl_.reset();
+}
+
+utils::optional<OpenRocksDB> RocksDatabase::open() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  if (!impl_) {
+    // database is not opened yet
+    rocksdb::DB* db_instance = nullptr;
+    rocksdb::Status result;
+    if (mode_ == Mode::ReadWrite) {

Review comment:
       I would recommend promoting such a warning to an error at the project level by adding `-Werror=switch-enum`/`/wL4061 /we4061` to minifi.
   
   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wswitch-default
   https://clang.llvm.org/docs/DiagnosticsReference.html#wswitch-enum
   https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4061?view=vs-2017
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475666940



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       also related: https://abseil.io/tips/177




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475565552



##########
File path: extensions/rocksdb-repos/RocksDatabase.h
##########
@@ -0,0 +1,98 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+
+#include "utils/OptionalUtils.h"
+#include "rocksdb/db.h"
+#include "rocksdb/options.h"
+#include "rocksdb/slice.h"
+#include "rocksdb/utilities/checkpoint.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+class RocksDatabase;
+
+// Not thread safe
+class OpenRocksDB {

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475660600



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,138 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }
+  return results;
+}
+
+rocksdb::Status OpenRocksDB::Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates) {
+  rocksdb::Status result = impl_->Write(options, updates);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key) {
+  rocksdb::Status result = impl_->Delete(options, key);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Merge(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+bool OpenRocksDB::GetProperty(const rocksdb::Slice& property, std::string* value) {
+  return impl_->GetProperty(property, value);
+}
+
+std::unique_ptr<rocksdb::Iterator> OpenRocksDB::NewIterator(const rocksdb::ReadOptions& options) {
+  return std::unique_ptr<rocksdb::Iterator>{impl_->NewIterator(options)};
+}
+
+rocksdb::Status OpenRocksDB::NewCheckpoint(rocksdb::Checkpoint **checkpoint) {
+  return rocksdb::Checkpoint::Create(impl_.get(), checkpoint);
+}
+
+rocksdb::Status OpenRocksDB::FlushWAL(bool sync) {
+  rocksdb::Status result = impl_->FlushWAL(sync);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::DB* OpenRocksDB::get() {
+  return impl_.get();
+}
+
+RocksDatabase::RocksDatabase(const rocksdb::Options& options, const std::string& name, Mode mode) : open_options_(options), db_name_(name), mode_(mode) {}
+
+void RocksDatabase::invalidate() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  // discard our own instance
+  impl_.reset();
+}
+
+utils::optional<OpenRocksDB> RocksDatabase::open() {
+  std::lock_guard<std::mutex> db_guard{ mtx_ };
+  if (!impl_) {
+    // database is not opened yet
+    rocksdb::DB* db_instance = nullptr;
+    rocksdb::Status result;
+    if (mode_ == Mode::ReadWrite) {

Review comment:
       I would use a `switch` so that we'll get a compiler warning if a new enum value is added and we forget to handle it.  But I realize that both of these events are unlikely, so I don't insist. :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476234461



##########
File path: extensions/rocksdb-repos/RocksDatabase.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDatabase.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+OpenRocksDB::OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl) : db_(std::move(db)), impl_(std::move(impl)) {}
+
+rocksdb::Status OpenRocksDB::Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value) {
+  rocksdb::Status result = impl_->Put(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+rocksdb::Status OpenRocksDB::Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value) {
+  rocksdb::Status result = impl_->Get(options, key, value);
+  if (result == rocksdb::Status::NoSpace()) {
+    db_->invalidate();
+  }
+  return result;
+}
+
+std::vector<rocksdb::Status> OpenRocksDB::MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values) {
+  std::vector<rocksdb::Status> results = impl_->MultiGet(options, keys, values);
+  for (const auto& result : results) {
+    if (result == rocksdb::Status::NoSpace()) {
+      db_->invalidate();
+    }
+  }

Review comment:
       nice catch (although `invalidate` is idempotent), I just added a `break`, because the proposed solution is too verbose for my liking, I dream of a day when we can do something like `results.some(_ == rocksdb::Status::NoSpace())` but that will probably come in `C++never`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475487913



##########
File path: extensions/rocksdb-repos/RocksDatabase.h
##########
@@ -0,0 +1,98 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+
+#include "utils/OptionalUtils.h"
+#include "rocksdb/db.h"
+#include "rocksdb/options.h"
+#include "rocksdb/slice.h"
+#include "rocksdb/utilities/checkpoint.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+class RocksDatabase;
+
+// Not thread safe
+class OpenRocksDB {

Review comment:
       `OpenRocksDB` could be non-copyable, as the intended use seems to be obtain_from_open() -> use -> discard.

##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -71,7 +75,7 @@ void FlowFileRepository::flush() {
     batch.Delete(keys[i]);
   }
 
-  auto operation = [this, &batch]() { return db_->Write(rocksdb::WriteOptions(), &batch); };
+  auto operation = [this, &batch, &opendb]() { return opendb->Write(rocksdb::WriteOptions(), &batch); };

Review comment:
       I think `this` does not need to be captured any longer (also at a few other places)

##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       Could the type of the field (and the constructor parameter) be `RocksDatabase&`?  Then we could call the constructor with `*db_` instead of `gsl::make_not_null<minifi::internal::RocksDatabase*>(db_.get())`.

##########
File path: extensions/rocksdb-repos/RocksDatabase.h
##########
@@ -0,0 +1,98 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+
+#include "utils/OptionalUtils.h"
+#include "rocksdb/db.h"
+#include "rocksdb/options.h"
+#include "rocksdb/slice.h"
+#include "rocksdb/utilities/checkpoint.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace internal {
+
+class RocksDatabase;
+
+// Not thread safe
+class OpenRocksDB {
+  friend class RocksDatabase;
+
+  OpenRocksDB(gsl::not_null<RocksDatabase*> db, gsl::not_null<std::shared_ptr<rocksdb::DB>> impl);
+
+ public:
+  rocksdb::Status Put(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value);
+
+  rocksdb::Status Get(const rocksdb::ReadOptions& options, const rocksdb::Slice& key, std::string* value);
+
+  std::vector<rocksdb::Status> MultiGet(const rocksdb::ReadOptions& options, const std::vector<rocksdb::Slice>& keys, std::vector<std::string>* values);
+
+  rocksdb::Status Write(const rocksdb::WriteOptions& options, rocksdb::WriteBatch* updates);
+
+  rocksdb::Status Delete(const rocksdb::WriteOptions& options, const rocksdb::Slice& key);
+
+  rocksdb::Status Merge(const rocksdb::WriteOptions& options, const rocksdb::Slice& key, const rocksdb::Slice& value);
+
+  bool GetProperty(const rocksdb::Slice& property, std::string* value);
+
+  rocksdb::Iterator* NewIterator(const rocksdb::ReadOptions& options);

Review comment:
       this could return a `unique_ptr`, as we always wrap the result into one

##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -134,14 +142,18 @@ void FlowFileRepository::prune_stored_flowfiles() {
     if (status.ok()) {

Review comment:
       Can we wrap `OpenForReadOnly` into a `RocksDatabase::openForReadOnly()`, too?  I think that would help simplify this code, and we could have one variable referring to the DB instead of three.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475582232



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       I was not aware of this convention; to me, a reference member variable sounds like a clear expression of "this object depends on `db_` being non-null and should not outlive it".  I would be interested to hear what others think.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475690750



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       but since nobody seems to share this feeling (here or the "internet") I will modify the constructor to take a reference 👍 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476472773



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -37,6 +37,10 @@ namespace core {
 namespace repository {
 
 void FlowFileRepository::flush() {
+  auto opendb = db_->open();
+  if (!opendb) {
+    return;

Review comment:
       an unsuccessful `open` now logs an error




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r475663017



##########
File path: extensions/rocksdb-repos/RocksDbStream.h
##########
@@ -160,7 +160,7 @@ class RocksDbStream : public io::BaseStream {
 
   std::string value_;
 
-  rocksdb::DB *db_;
+  gsl::not_null<minifi::internal::RocksDatabase*> db_;

Review comment:
       https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#note-392 Last sentence of "Exceptions":
   > Note that using a reference member is almost always wrong.
   
   Sadly there is no explanation and I couldn't find one elsewhere either.
   
   I was not aware of the convention either, that taking a reference indicates not storing it. Do you have any resources explaining it? My disk space watchdog PR is affected because it takes ctor args by reference just to store them in a `gsl::not_null<T*>` member.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a change in pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on a change in pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877#discussion_r476437225



##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -37,6 +37,10 @@ namespace core {
 namespace repository {
 
 void FlowFileRepository::flush() {
+  auto opendb = db_->open();
+  if (!opendb) {
+    return;

Review comment:
       Is this okay, shouldn't we log or throw?

##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -194,22 +201,27 @@ bool FlowFileRepository::ExecuteWithRetry(std::function<rocksdb::Status()> opera
  * Returns True if there is data to interrogate.
  * @return true if our db has data stored.
  */
-bool FlowFileRepository::need_checkpoint(){
-  std::unique_ptr<rocksdb::Iterator> it = std::unique_ptr<rocksdb::Iterator>(db_->NewIterator(rocksdb::ReadOptions()));
+bool FlowFileRepository::need_checkpoint(minifi::internal::OpenRocksDB& opendb){
+  auto it = opendb.NewIterator(rocksdb::ReadOptions());
   for (it->SeekToFirst(); it->Valid(); it->Next()) {

Review comment:
       Why is this a loop if it returns the first time?

##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -91,14 +95,18 @@ void FlowFileRepository::flush() {
 }
 
 void FlowFileRepository::printStats() {
+  auto opendb = db_->open();
+  if (!opendb) {
+    return;

Review comment:
       Is this okay, shouldn't we log or throw?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #877: MINIFICPP-1339 - Reopen rocksdb database when space becomes available on the disk

Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #877:
URL: https://github.com/apache/nifi-minifi-cpp/pull/877


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org