kangkaisen commented on a change in pull request #3508:
URL: https://github.com/apache/incubator-doris/pull/3508#discussion_r422596311



##########
File path: be/src/olap/memory/buffer.h
##########
@@ -0,0 +1,74 @@
+// 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 "olap/memory/common.h"
+
+namespace doris {
+namespace memory {
+
+// A generic buffer holding column base and delta data
+// It can be considered as an array of any primitive type, but it does not
+// have compile time type information, user can use utility method as<T> to
+// get typed array view.
+class Buffer {
+public:
+    Buffer() = default;
+    ~Buffer();
+
+    // allocate memory for this buffer, with buffer byte size of bsize
+    Status alloc(size_t bsize);
+
+    // clear buffer, free memory
+    void clear();
+
+    // set all memory content to zero
+    void set_zero();
+
+    // return true if this buffer is not empty
+    operator bool() const { return _data != nullptr; }
+
+    // returns a direct pointer to the memory array
+    const uint8_t* data() const { return _data; }
+
+    // returns a direct pointer to the memory array
+    uint8_t* data() { return _data; }

Review comment:
       would better naming mutable_data().

##########
File path: be/src/olap/memory/column.cpp
##########
@@ -0,0 +1,124 @@
+// 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 "olap/memory/column.h"
+
+namespace doris {
+namespace memory {
+
+Column::Column(const ColumnSchema& cs, ColumnType storage_type, uint64_t 
version)
+        : _cs(cs), _storage_type(storage_type), _base_idx(0) {
+    _base.reserve(64);

Review comment:
       Why is 64 ? Which should be a const value.

##########
File path: be/src/olap/memory/column.h
##########
@@ -0,0 +1,101 @@
+// 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 "olap/memory/column_block.h"
+#include "olap/memory/column_delta.h"
+#include "olap/memory/common.h"
+#include "olap/memory/schema.h"
+
+namespace doris {
+namespace memory {
+
+class ColumnReader;
+class ColumnWriter;
+
+// Column store all the data of a column, including base and deltas.
+// It supports single-writer multi-reader concurrency.
+// It's properties are all immutable except _base and _versions.
+// _base and _versions use std::vector, which is basically thread-safe
+// in-practice for single-writer/multi-reader access, if there isn't
+// any over-capacity realloc or delta compaction/GC caused data change.
+// When these situations occur, we do a copy-on-write.
+//
+// TODO: add column read&writer
+class Column : public RefCountedThreadSafe<Column> {
+public:
+    static const uint32_t BLOCK_SIZE = 1 << 16;
+    static const uint32_t BLOCK_MASK = 0xffff;
+
+    // create a Column which provided column schema, underlying storage_type 
and initial version
+    Column(const ColumnSchema& cs, ColumnType storage_type, uint64_t version);
+
+    // copy-on-write a new Column with new capacity
+    Column(const Column& rhs, size_t new_base_capacity, size_t 
new_version_capacity);
+
+    // get column schema
+    const ColumnSchema& schema() { return _cs; }
+
+    // get memory usage in bytes
+    size_t memory() const;
+
+    string debug_string() const;
+
+    // read this Column at a specific version, get a reader for this Column
+    // support multiple concurrent readers
+    Status read(uint64_t version, std::unique_ptr<ColumnReader>* reader);
+
+    // write this Column, get a writer for this Column
+    // caller needs to make sure there is only one or no writer exists at any 
time
+    Status write(std::unique_ptr<ColumnWriter>* writer);
+
+private:
+    ColumnSchema _cs;
+    // For some types the storage_type may be different from actual type from 
schema.
+    // For example, string stored in dictionary, so column_block store a 
integer id,
+    // and the storage type may change as the dictionary grows, e.g. from 
uint8 to uint16
+    ColumnType _storage_type;
+    // base's position at _versions vector
+    ssize_t _base_idx;

Review comment:
       Why use ssize_t?  _base_idx could be negative?

##########
File path: be/src/olap/memory/column_block.h
##########
@@ -0,0 +1,53 @@
+// 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 "olap/memory/buffer.h"
+#include "olap/memory/common.h"
+
+namespace doris {
+namespace memory {
+
+// ColumnBlock stores one block of data for a Column
+class ColumnBlock : public RefCountedThreadSafe<ColumnBlock> {
+public:
+    ColumnBlock() = default;
+
+    size_t memory() const;
+
+    Buffer& data() { return _data; }
+
+    Buffer& nulls() { return _nulls; }
+
+    Status alloc(size_t size, size_t esize);

Review comment:
       `esize ` means `element_size`? would better add a comment for this 
method.




----------------------------------------------------------------
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



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

Reply via email to