Skip to content

Commit 4ba2f1c

Browse files
authored
Merge branch 'master' into fix-restore-schema
2 parents b6690a5 + f66e517 commit 4ba2f1c

File tree

86 files changed

+5598
-868
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5598
-868
lines changed

be/src/olap/rowset/segment_v2/bloom_filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class BloomFilter {
194194
/// Bloom filters must have equal size and seed.
195195
virtual bool contains(const BloomFilter& bf_) const { return true; };
196196

197-
virtual char* data() const { return _data; }
197+
virtual const char* data() const { return _data; }
198198

199199
size_t num_bytes() const { return _num_bytes; }
200200

be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,12 @@ bool DorisRAMFSDirectory::list(std::vector<std::string>* names) const {
738738

739739
bool DorisRAMFSDirectory::fileExists(const char* name) const {
740740
std::lock_guard<std::mutex> wlock(_this_lock);
741-
return filesMap->exists((char*)name);
741+
return filesMap->exists(name);
742742
}
743743

744744
int64_t DorisRAMFSDirectory::fileModified(const char* name) const {
745745
std::lock_guard<std::mutex> wlock(_this_lock);
746-
auto* f = filesMap->get((char*)name);
746+
auto* f = filesMap->get(name);
747747
DBUG_EXECUTE_IF("DorisRAMFSDirectory::fileModified_file_not_found", { f = nullptr; })
748748
if (f == nullptr) {
749749
_CLTHROWA(CL_ERR_IO, fmt::format("NOT FOUND File {}.", name).c_str());
@@ -755,7 +755,7 @@ void DorisRAMFSDirectory::touchFile(const char* name) {
755755
lucene::store::RAMFile* file = nullptr;
756756
{
757757
std::lock_guard<std::mutex> wlock(_this_lock);
758-
file = filesMap->get((char*)name);
758+
file = filesMap->get(name);
759759
DBUG_EXECUTE_IF("DorisRAMFSDirectory::touchFile_file_not_found", { file = nullptr; })
760760
if (file == nullptr) {
761761
_CLTHROWA(CL_ERR_IO, fmt::format("NOT FOUND File {}.", name).c_str());
@@ -775,7 +775,7 @@ void DorisRAMFSDirectory::touchFile(const char* name) {
775775

776776
int64_t DorisRAMFSDirectory::fileLength(const char* name) const {
777777
std::lock_guard<std::mutex> wlock(_this_lock);
778-
auto* f = filesMap->get((char*)name);
778+
auto* f = filesMap->get(name);
779779
DBUG_EXECUTE_IF("DorisRAMFSDirectory::fileLength_file_not_found", { f = nullptr; })
780780
if (f == nullptr) {
781781
_CLTHROWA(CL_ERR_IO, fmt::format("NOT FOUND File {}.", name).c_str());
@@ -786,7 +786,7 @@ int64_t DorisRAMFSDirectory::fileLength(const char* name) const {
786786
bool DorisRAMFSDirectory::openInput(const char* name, lucene::store::IndexInput*& ret,
787787
CLuceneError& error, int32_t bufferSize) {
788788
std::lock_guard<std::mutex> wlock(_this_lock);
789-
auto* file = filesMap->get((char*)name);
789+
auto* file = filesMap->get(name);
790790
DBUG_EXECUTE_IF("DorisRAMFSDirectory::openInput_file_not_found", { file = nullptr; })
791791
if (file == nullptr) {
792792
error.set(CL_ERR_IO,
@@ -805,7 +805,7 @@ void DorisRAMFSDirectory::close() {
805805

806806
bool DorisRAMFSDirectory::doDeleteFile(const char* name) {
807807
std::lock_guard<std::mutex> wlock(_this_lock);
808-
auto itr = filesMap->find((char*)name);
808+
auto itr = filesMap->find(name);
809809
if (itr != filesMap->end()) {
810810
SCOPED_LOCK_MUTEX(this->THIS_LOCK);
811811
sizeInBytes -= itr->second->sizeInBytes;
@@ -821,15 +821,15 @@ bool DorisRAMFSDirectory::deleteDirectory() {
821821

822822
void DorisRAMFSDirectory::renameFile(const char* from, const char* to) {
823823
std::lock_guard<std::mutex> wlock(_this_lock);
824-
auto itr = filesMap->find((char*)from);
824+
auto itr = filesMap->find(from);
825825

826826
/* DSR:CL_BUG_LEAK:
827827
** If a file named $to already existed, its old value was leaked.
828828
** My inclination would be to prevent this implicit deletion with an
829829
** exception, but it happens routinely in CLucene's internals (e.g., during
830830
** IndexWriter.addIndexes with the file named 'segments'). */
831-
if (filesMap->exists((char*)to)) {
832-
auto itr1 = filesMap->find((char*)to);
831+
if (filesMap->exists(to)) {
832+
auto itr1 = filesMap->find(to);
833833
SCOPED_LOCK_MUTEX(this->THIS_LOCK);
834834
sizeInBytes -= itr1->second->sizeInBytes;
835835
filesMap->removeitr(itr1);
@@ -855,8 +855,8 @@ lucene::store::IndexOutput* DorisRAMFSDirectory::createOutput(const char* name)
855855
std::lock_guard<std::mutex> wlock(_this_lock);
856856

857857
// get the actual pointer to the output name
858-
char* n = nullptr;
859-
auto itr = filesMap->find(const_cast<char*>(name));
858+
const char* n = nullptr;
859+
auto itr = filesMap->find(name);
860860
DBUG_EXECUTE_IF("DorisRAMFSDirectory::createOutput_itr_filesMap_end",
861861
{ itr = filesMap->end(); })
862862
if (itr != filesMap->end()) {

be/src/olap/rowset/segment_v2/inverted_index_fs_directory.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ class CLUCENE_EXPORT DorisFSDirectory : public lucene::store::Directory {
102102

103103
class CLUCENE_EXPORT DorisRAMFSDirectory : public DorisFSDirectory {
104104
protected:
105-
using FileMap =
106-
lucene::util::CLHashMap<char*, lucene::store::RAMFile*, lucene::util::Compare::Char,
107-
lucene::util::Equals::Char, lucene::util::Deletor::acArray,
108-
lucene::util::Deletor::Object<lucene::store::RAMFile>>;
105+
using FileMap = lucene::util::CLHashMap<const char*, lucene::store::RAMFile*,
106+
lucene::util::Compare::Char, lucene::util::Equals::Char,
107+
lucene::util::Deletor::cacArray,
108+
lucene::util::Deletor::Object<lucene::store::RAMFile>>;
109109

110110
// unlike the java Hashtable, FileMap is not synchronized, and all access must be protected by a lock
111111
FileMap* filesMap;

be/src/olap/rowset/segment_v2/inverted_index_writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ Status InvertedIndexColumnWriter<field_type>::add_array_values(size_t field_size
542542
return Status::InternalError("field or index writer is null in inverted index writer");
543543
}
544544
for (int i = 0; i < count; ++i) {
545-
auto* item_data_ptr = const_cast<CollectionValue*>(values)->mutable_data();
545+
const auto* item_data_ptr = values->data();
546546
std::vector<std::string> strings;
547547

548548
for (size_t j = 0; j < values->length(); ++j) {
@@ -561,7 +561,7 @@ Status InvertedIndexColumnWriter<field_type>::add_array_values(size_t field_size
561561
}
562562
} else if constexpr (field_is_numeric_type(field_type)) {
563563
for (int i = 0; i < count; ++i) {
564-
auto* item_data_ptr = const_cast<CollectionValue*>(values)->mutable_data();
564+
const auto* item_data_ptr = values->data();
565565

566566
for (size_t j = 0; j < values->length(); ++j) {
567567
const auto* p = reinterpret_cast<const CppType*>(item_data_ptr);

be/src/olap/rowset/segment_v2/ngram_bloom_filter.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class NGramBloomFilter : public BloomFilter {
4141
void add_bytes(const char* data, size_t len) override;
4242
bool contains(const BloomFilter& bf_) const override;
4343
Status init(const char* buf, size_t size, HashStrategyPB strategy) override;
44-
char* data() const override {
45-
return reinterpret_cast<char*>(const_cast<uint64_t*>(filter.data()));
46-
}
44+
const char* data() const override { return reinterpret_cast<const char*>(filter.data()); }
4745
size_t size() const override { return _size; }
4846
void add_hash(uint64_t) override {}
4947
bool test_hash(uint64_t hash) const override { return true; }

be/src/olap/rowset/segment_v2/page_io.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Status PageIO::read_and_decompress_page_(const PageReadOptions& opts, PageHandle
176176
if (opts.verify_checksum) {
177177
uint32_t expect = decode_fixed32_le((uint8_t*)page_slice.data + page_slice.size - 4);
178178
uint32_t actual = crc32c::Value(page_slice.data, page_slice.size - 4);
179+
// here const_cast is used for testing.
179180
InjectionContext ctx = {&actual, const_cast<PageReadOptions*>(&opts)};
180181
(void)ctx;
181182
TEST_INJECTION_POINT_CALLBACK("PageIO::read_and_decompress_page:crc_failure_inj", &ctx);

be/src/olap/rowset/segment_v2/segment_writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ void SegmentWriter::_maybe_invalid_row_cache(const std::string& key) {
375375
}
376376
}
377377

378-
void SegmentWriter::_serialize_block_to_row_column(vectorized::Block& block) {
378+
void SegmentWriter::_serialize_block_to_row_column(const vectorized::Block& block) {
379379
if (block.rows() == 0) {
380380
return;
381381
}
@@ -697,7 +697,7 @@ Status SegmentWriter::append_block(const vectorized::Block* block, size_t row_po
697697
// or it's schema change write(since column data type maybe changed, so we should reubild)
698698
if (_opts.write_type == DataWriteType::TYPE_DIRECT ||
699699
_opts.write_type == DataWriteType::TYPE_SCHEMA_CHANGE) {
700-
_serialize_block_to_row_column(*const_cast<vectorized::Block*>(block));
700+
_serialize_block_to_row_column(*block);
701701
}
702702

703703
_olap_data_convertor->set_source_content(block, row_pos, num_rows);

be/src/olap/rowset/segment_v2/segment_writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class SegmentWriter {
192192
void set_min_max_key(const Slice& key);
193193
void set_min_key(const Slice& key);
194194
void set_max_key(const Slice& key);
195-
void _serialize_block_to_row_column(vectorized::Block& block);
195+
void _serialize_block_to_row_column(const vectorized::Block& block);
196196
Status _generate_primary_key_index(
197197
const std::vector<const KeyCoder*>& primary_key_coders,
198198
const std::vector<vectorized::IOlapColumnDataAccessor*>& primary_key_columns,

be/src/olap/rowset/segment_v2/variant/hierarchical_data_iterator.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,16 @@ Status HierarchicalDataIterator::_process_sparse_column(
381381
// Case 1: subcolumn already created, append this row's value into it.
382382
if (auto it = subcolumns_from_sparse_column.find(sub_path);
383383
it != subcolumns_from_sparse_column.end()) {
384-
const auto& data = ColumnVariant::deserialize_from_sparse_column(
385-
&src_sparse_data_values, lower_bound_index);
386-
it->second.insert(data.first, data.second);
384+
it->second.deserialize_from_sparse_column(&src_sparse_data_values,
385+
lower_bound_index);
387386
}
388387
// Case 2: subcolumn not created yet and we still have quota → create it and insert.
389388
else if (subcolumns_from_sparse_column.size() < count) {
390389
// Initialize subcolumn with current logical row index i to align sizes.
391390
ColumnVariant::Subcolumn subcolumn(/*size*/ i, /*is_nullable*/ true,
392391
false);
393-
const auto& data = ColumnVariant::deserialize_from_sparse_column(
394-
&src_sparse_data_values, lower_bound_index);
395-
subcolumn.insert(data.first, data.second);
392+
subcolumn.deserialize_from_sparse_column(&src_sparse_data_values,
393+
lower_bound_index);
396394
subcolumns_from_sparse_column.emplace(sub_path, std::move(subcolumn));
397395
}
398396
// Case 3: quota exhausted → keep the key/value in container's sparse column.
@@ -416,9 +414,8 @@ Status HierarchicalDataIterator::_process_sparse_column(
416414
// return Status::InternalError("Failed to add subcolumn for sparse column");
417415
// }
418416
}
419-
const auto& data = ColumnVariant::deserialize_from_sparse_column(
417+
container_variant.get_subcolumn({})->deserialize_from_sparse_column(
420418
&src_sparse_data_values, lower_bound_index);
421-
container_variant.get_subcolumn({})->insert(data.first, data.second);
422419
}
423420
}
424421
// if root was created, and not seen in sparse data, insert default

be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void VerticalSegmentWriter::_maybe_invalid_row_cache(const std::string& key) con
355355
}
356356
}
357357

358-
void VerticalSegmentWriter::_serialize_block_to_row_column(vectorized::Block& block) {
358+
void VerticalSegmentWriter::_serialize_block_to_row_column(const vectorized::Block& block) {
359359
if (block.rows() == 0) {
360360
return;
361361
}
@@ -948,7 +948,7 @@ Status VerticalSegmentWriter::write_batch() {
948948
_opts.write_type == DataWriteType::TYPE_SCHEMA_CHANGE) {
949949
for (auto& data : _batched_blocks) {
950950
// TODO: maybe we should pass range to this method
951-
_serialize_block_to_row_column(*const_cast<vectorized::Block*>(data.block));
951+
_serialize_block_to_row_column(*data.block);
952952
}
953953
}
954954

0 commit comments

Comments
 (0)