chaoyli commented on a change in pull request #429: add rowset meta manager URL: https://github.com/apache/incubator-doris/pull/429#discussion_r241632250
########## File path: be/src/olap/rowset/rowset_meta_manager.cpp ########## @@ -0,0 +1,147 @@ +// 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/rowset/rowset_meta_manager.h" + +#include <vector> +#include <sstream> +#include <string> +#include <fstream> +#include <boost/algorithm/string/trim.hpp> + +#include "olap/olap_define.h" +#include "olap/storage_engine.h" +#include "common/logging.h" +#include "json2pb/json_to_pb.h" +#include "json2pb/pb_to_json.h" + +namespace doris { + +const std::string ROWSET_PREFIX = "rst_"; + +NewStatus convert_meta_status(OLAPStatus status) { + if (status == OLAP_SUCCESS) { + return NewStatus::OK(); + } else { + std::string error_msg = "meta operation failed"; + LOG(WARNING) << error_msg; + return NewStatus::IOError(error_msg); + } +} + +NewStatus RowsetMetaManager::get_rowset_meta(OlapMeta* meta, int64_t rowset_id, RowsetMeta* rowset_meta) { + std::string key = ROWSET_PREFIX + std::to_string(rowset_id); + std::string value; + OLAPStatus s = meta->get(META_COLUMN_FAMILY_INDEX, key, value); + if (s == OLAP_ERR_META_KEY_NOT_FOUND) { + std::string error_msg = "rowset id:" + std::to_string(rowset_id) + " not found."; + LOG(WARNING) << error_msg; + return NewStatus::NotFound(error_msg); + } else if (s != OLAP_SUCCESS) { + std::string error_msg = "load rowset id:" + std::to_string(rowset_id) + " failed."; + LOG(WARNING) << error_msg; + return NewStatus::IOError(error_msg); + } + RowsetMetaPb rowset_meta_pb; + bool parsed = rowset_meta_pb.ParseFromString(value); + if (!parsed) { + std::string error_msg = "parser rowset pb failed. rowset id:" + std::to_string(rowset_id); + LOG(WARNING) << error_msg; + return NewStatus::Corruption(error_msg); + } + rowset_meta->init(rowset_meta_pb); + return NewStatus::OK(); +} + +NewStatus RowsetMetaManager::get_json_rowset_meta(OlapMeta* meta, int64_t rowset_id, std::string* json_rowset_meta) { + RowsetMeta rowset_meta; + NewStatus s = get_rowset_meta(meta, rowset_id, &rowset_meta); + if (!s.ok()) { + return s; + } + json2pb::Pb2JsonOptions json_options; + json_options.pretty_json = true; + RowsetMetaPb rowset_meta_pb; + rowset_meta.get_rowset_meta_pb(&rowset_meta_pb); + json2pb::ProtoMessageToJson(rowset_meta_pb, json_rowset_meta, json_options); + return NewStatus::OK(); +} + +NewStatus RowsetMetaManager::save(OlapMeta* meta, int64_t rowset_id, RowsetMeta* rowset_meta) { + std::string key = ROWSET_PREFIX + std::to_string(rowset_id); + RowsetMetaPb rowset_meta_pb; + rowset_meta->get_rowset_meta_pb(&rowset_meta_pb); Review comment: RowsetMetaManager should not know RowsetMetaPB. RowsetMeta is stored as pb or another format is transparent to RowsetMetaManager. Instead, Rowset provide a serialize interface to convert pb to bytes. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
