gaodayue commented on a change in pull request #2782: Add file cache for v2
URL: https://github.com/apache/incubator-doris/pull/2782#discussion_r367823797
 
 

 ##########
 File path: be/src/util/file_cache.cpp
 ##########
 @@ -0,0 +1,416 @@
+// 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 "util/file_cache.h"
+
+#include <atomic>
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <mutex>
+#include <ostream>
+#include <string>
+#include <utility>
+#include <vector>
+#include <chrono>
+#include <functional>
+
+#include "env/env.h"
+#include "gutil/strings/substitute.h"
+
+namespace doris {
+
+namespace internal {
+
+template <class FileType>
+class OpenedFileHandle;
+
+// Encapsulates common descriptor fields and methods.
+template <class FileType>
+class BaseDescriptor {
+public:
+    BaseDescriptor(FileCache<FileType>* file_cache, const std::string& 
filename)
+        : _file_cache(file_cache), _file_name(filename) { }
+
+    ~BaseDescriptor() {
+        // The (now expired) weak_ptr remains in '_descriptors', to be removed
+        // by the next call to RunDescriptorExpiry(). Removing it here would
+        // risk a deadlock on recursive acquisition of '_lock'.
+
+        if (deleted()) {
+            cache()->erase(filename());
+
+            WARN_IF_ERROR(env()->delete_file(filename()), "delete file 
failed:");
+        }
+    }
+
+    // Insert a pointer to an open file object(FileType*) into the file cache 
with the
+    // filename as the cache key.
+    //
+    // Returns a handle to the inserted entry. The handle always contains an
+    // open file.
+    OpenedFileHandle<FileType> insert_into_cache(void* file_ptr) const {
+        // TODO(hkp)
+        auto deleter = [](const doris::CacheKey& key, void* value) {
+            delete (FileType*)value;
+        };
+        FileType* file = reinterpret_cast<FileType*>(file_ptr);
+        CacheKey key(file->file_name());
+        auto lru_handle = cache()->insert(key, file_ptr, sizeof(file_ptr), 
deleter);
+        return OpenedFileHandle<FileType>(this, lru_handle);
+    }
+
+    // Retrieves a pointer to an open file object from the file cache with the
+    // filename as the cache key.
+    //
+    // Returns a handle to the looked up entry. The handle may or may not
+    // contain an open file, depending on whether the cache hit or missed.
+    OpenedFileHandle<FileType> lookup_from_cache() const {
+        // TODO(hkp): use lru_cache to replace
 
 Review comment:
   what does the TODO mean?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to