JayjeetAtGithub commented on a change in pull request #10431: URL: https://github.com/apache/arrow/pull/10431#discussion_r681628012
########## File path: cpp/src/arrow/dataset/file_skyhook.cc ########## @@ -0,0 +1,280 @@ +// 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 "arrow/dataset/file_skyhook.h" + +#include <mutex> + +#include "arrow/api.h" +#include "arrow/compute/exec/expression.h" +#include "arrow/dataset/dataset_internal.h" +#include "arrow/dataset/file_base.h" +#include "arrow/dataset/file_ipc.h" +#include "arrow/dataset/file_parquet.h" +#include "arrow/filesystem/filesystem.h" +#include "arrow/filesystem/path_util.h" +#include "arrow/filesystem/util_internal.h" +#include "arrow/util/checked_cast.h" +#include "arrow/util/compression.h" +#include "arrow/util/iterator.h" +#include "arrow/util/logging.h" +#include "parquet/arrow/reader.h" +#include "parquet/file_reader.h" + +#include <flatbuffers/flatbuffers.h> + +#include "generated/ScanRequest_generated.h" + +namespace arrow { + +namespace flatbuf = org::apache::arrow::flatbuf; + +namespace dataset { + +namespace connection { + +std::mutex connection_mutex; + +RadosConnection::~RadosConnection() { Shutdown(); } + +Status RadosConnection::Connect() { + if (connected) { + return Status::OK(); + } + + // Locks the mutex. Only one thread can pass here at a time. + // Another thread handled the connection already. + std::unique_lock<std::mutex> lock(connection_mutex); + if (connected) { + return Status::OK(); + } + connected = true; + + if (rados->init2(ctx.user_name.c_str(), ctx.cluster_name.c_str(), 0)) + return Status::Invalid("librados::init2 returned non-zero exit code."); + + if (rados->conf_read_file(ctx.ceph_config_path.c_str())) + return Status::Invalid("librados::conf_read_file returned non-zero exit code."); + + if (rados->connect()) + return Status::Invalid("librados::connect returned non-zero exit code."); + + if (rados->ioctx_create(ctx.data_pool.c_str(), ioCtx)) + return Status::Invalid("librados::ioctx_create returned non-zero exit code."); + + return Status::OK(); +} + +Status RadosConnection::Shutdown() { + rados->shutdown(); + return Status::OK(); +} + +} // namespace connection + +/// \brief A ScanTask to scan a file fragment in Skyhook format. +class SkyhookScanTask : public ScanTask { + public: + SkyhookScanTask(std::shared_ptr<ScanOptions> options, + std::shared_ptr<Fragment> fragment, FileSource source, + std::shared_ptr<SkyhookDirectObjectAccess> doa, int fragment_format) + : ScanTask(std::move(options), std::move(fragment)), + source_(std::move(source)), + doa_(std::move(doa)), + fragment_format_(fragment_format) {} + + Result<RecordBatchIterator> Execute() override { + struct stat st {}; + ARROW_RETURN_NOT_OK(doa_->Stat(source_.path(), st)); + + ceph::bufferlist request; + ARROW_RETURN_NOT_OK( + SerializeScanRequest(options_, fragment_format_, st.st_size, request)); + + ceph::bufferlist result; + ARROW_RETURN_NOT_OK(doa_->Exec(st.st_ino, "scan_op", request, result)); + + RecordBatchVector batches; + ARROW_RETURN_NOT_OK(DeserializeTable(batches, result, !options_->use_threads)); Review comment: Looks like the decompression API also needs to be futurized for the async scanner to work. Since, it is not yet futurized, looks like we need to do this check to avoid nested threading. -- 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. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org