In previous, the counter in `profile` may be updated when close the file reader. And the file reader may be closed when the object being deconstruted. But at that time, the `profile` object may already be deleted, causing NPE and BE will crash. This PR try to fix this issue: 1. Remove the "profile counter update" logic from all `close()` method. 2. Add a new interface `ProfileCollector` It has 2 methods: - `collect_profile_at_runtime()` It can be called at runtime, eg, in every `get_next_block()` method. So that the counter in profile can be updated at runtime. - `collect_profile_before_close()` Should be called before the object call `close()`. And it will only be called once. 3. Derived from `ProfileCollector` All classes which may update the profile counter in `close()` method should extends the `ProfileCollector`. Such as `GenericReader`, etc. And implement `collect_profile_before_close()` And `collect_profile_before_close()` will be called in `scanner->mark_to_need_to_close()`.
82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
// 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 <stddef.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
#include "common/status.h"
|
|
#include "exec/olap_common.h"
|
|
#include "vec/exec/format/generic_reader.h"
|
|
#include "vec/exec/jni_connector.h"
|
|
|
|
namespace doris {
|
|
class RuntimeProfile;
|
|
class RuntimeState;
|
|
class SlotDescriptor;
|
|
namespace vectorized {
|
|
class Block;
|
|
} // namespace vectorized
|
|
struct TypeDescriptor;
|
|
} // namespace doris
|
|
|
|
namespace doris::vectorized {
|
|
|
|
/**
|
|
* The demo usage of JniReader, showing how to read data from java scanner.
|
|
* The java side is also a mock reader that provide values for each type.
|
|
* This class will only be retained during the functional testing phase to verify that
|
|
* the communication and data exchange with the jvm are correct.
|
|
*/
|
|
class MockJniReader : public GenericReader {
|
|
public:
|
|
MockJniReader(const std::vector<SlotDescriptor*>& file_slot_descs, RuntimeState* state,
|
|
RuntimeProfile* profile);
|
|
|
|
~MockJniReader() override = default;
|
|
|
|
Status get_next_block(Block* block, size_t* read_rows, bool* eof) override;
|
|
|
|
Status get_columns(std::unordered_map<std::string, TypeDescriptor>* name_to_type,
|
|
std::unordered_set<std::string>* missing_cols) override;
|
|
|
|
Status init_reader(
|
|
std::unordered_map<std::string, ColumnValueRangeType>* colname_to_value_range);
|
|
|
|
protected:
|
|
void _collect_profile_before_close() override {
|
|
if (_jni_connector != nullptr) {
|
|
_jni_connector->collect_profile_before_close();
|
|
}
|
|
}
|
|
|
|
private:
|
|
const std::vector<SlotDescriptor*>& _file_slot_descs;
|
|
RuntimeState* _state = nullptr;
|
|
RuntimeProfile* _profile = nullptr;
|
|
std::unordered_map<std::string, ColumnValueRangeType>* _colname_to_value_range;
|
|
std::unique_ptr<JniConnector> _jni_connector;
|
|
};
|
|
|
|
} // namespace doris::vectorized
|