acelyc111 commented on a change in pull request #651: URL: https://github.com/apache/incubator-pegasus/pull/651#discussion_r536947297
########## File path: src/server/rocksdb_wrapper.h ########## @@ -0,0 +1,58 @@ +/* + * 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 <dsn/dist/replication/replica_base.h> + +namespace rocksdb { +class DB; +class ReadOptions; +} // namespace rocksdb + +namespace dsn { +class perf_counter_wrapper; +} // namespace dsn + +namespace pegasus { +namespace server { +struct db_get_context; +class pegasus_server_impl; + +static constexpr int FAIL_DB_GET = -104; Review comment: Could you define it in cpp? And what does '-104' mean? ########## File path: src/server/rocksdb_wrapper.cpp ########## @@ -0,0 +1,68 @@ +/* + * 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 "rocksdb_wrapper.h" + +#include <rocksdb/db.h> +#include "pegasus_write_service_impl.h" + +namespace pegasus { +namespace server { + +rocksdb_wrapper::rocksdb_wrapper(pegasus_server_impl *server) + : replica_base(server), + _db(server->_db), + _rd_opts(server->_data_cf_rd_opts), + _pegasus_data_version(server->_pegasus_data_version), + _pfc_recent_expire_count(server->_pfc_recent_expire_count) +{ +} + +int rocksdb_wrapper::get(dsn::string_view raw_key, /*out*/ db_get_context *ctx) +{ + FAIL_POINT_INJECT_F("db_get", [](dsn::string_view) -> int { return FAIL_DB_GET; }); + + rocksdb::Status s = _db->Get(_rd_opts, utils::to_rocksdb_slice(raw_key), &(ctx->raw_value)); + if (dsn_likely(s.ok())) { + // success + ctx->found = true; + ctx->expire_ts = pegasus_extract_expire_ts(_pegasus_data_version, ctx->raw_value); + if (check_if_ts_expired(utils::epoch_now(), ctx->expire_ts)) { + ctx->expired = true; + _pfc_recent_expire_count->increment(); + } + return 0; Review comment: When do refactor, ERR_OK is more meanful than '0' ---------------------------------------------------------------- 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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
