wgtmac commented on code in PR #1033: URL: https://github.com/apache/iceberg-cpp/pull/1033#discussion_r4320696380
########## src/iceberg/util/scheduled_executor_internal.h: ########## @@ -0,0 +1,125 @@ +/* + * 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 <chrono> +#include <condition_variable> +#include <cstdint> +#include <memory> +#include <mutex> +#include <optional> +#include <queue> +#include <thread> +#include <unordered_set> +#include <vector> + +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" +#include "iceberg/util/executor.h" + +namespace iceberg::internal { + +class ScheduledExecutorState; + +using ScheduledTaskRejection = FnOnce<void(Status)>; + +class ICEBERG_EXPORT ScheduledTask { + public: + ScheduledTask() = default; + ScheduledTask(std::weak_ptr<ScheduledExecutorState> state, uint64_t id) + : state_(std::move(state)), id_(id) {} + + void Cancel(); + bool IsValid() const { return id_.has_value() && !state_.expired(); } + + private: + std::weak_ptr<ScheduledExecutorState> state_; + std::optional<uint64_t> id_; Review Comment: Clarified in bb30175e9: ScheduledTask is intentionally a copyable, non-owning cancellation token, not a uniquely owned future. Cancel is idempotent for the shared registration and clears only that token. IsValid tests whether the token has an ID and its owner state exists; it does not report pending task status or cancellation through another copy. The contract is now explicit, and the cancellation test exercises copying, cancelling through both copies, and their independent validity. ########## src/iceberg/util/scheduled_executor_internal.h: ########## @@ -0,0 +1,114 @@ +/* + * 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 <chrono> +#include <condition_variable> +#include <cstdint> +#include <memory> +#include <mutex> +#include <optional> +#include <unordered_set> + +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" +#include "iceberg/util/executor.h" + +namespace iceberg::internal { + +class SharedTimer; +class SharedTimerState; +class ScheduledExecutorState; + +using ScheduledTaskRejection = FnOnce<void(Status)>; + +class ICEBERG_EXPORT ScheduledTask { + public: + ScheduledTask() = default; + ScheduledTask(std::weak_ptr<ScheduledExecutorState> state, uint64_t id) + : state_(std::move(state)), id_(id) {} + + void Cancel(); + bool IsValid() const { return id_.has_value() && !state_.expired(); } + + private: + std::weak_ptr<ScheduledExecutorState> state_; + std::optional<uint64_t> id_; +}; Review Comment: Addressed in bb30175e9 with the explicit synchronization contract. Concurrent operations on the same ScheduledTask object require external synchronization; separate copies may be cancelled concurrently. The OAuth session already protects its token using refresh_mutex_. This documents the actual lightweight token semantics without introducing redundant per-handle locks. ########## src/iceberg/util/scheduled_executor_internal.h: ########## @@ -0,0 +1,114 @@ +/* + * 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 <chrono> +#include <condition_variable> +#include <cstdint> +#include <memory> +#include <mutex> +#include <optional> +#include <unordered_set> + +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" +#include "iceberg/util/executor.h" + +namespace iceberg::internal { + +class SharedTimer; +class SharedTimerState; +class ScheduledExecutorState; + +using ScheduledTaskRejection = FnOnce<void(Status)>; + +class ICEBERG_EXPORT ScheduledTask { + public: + ScheduledTask() = default; + ScheduledTask(std::weak_ptr<ScheduledExecutorState> state, uint64_t id) + : state_(std::move(state)), id_(id) {} + + void Cancel(); + bool IsValid() const { return id_.has_value() && !state_.expired(); } + + private: Review Comment: Addressed in bb30175e9 by specifying the intended copyable-token semantics. IsValid is handle/state validity, not a query of the task registration, and cancelling one copy does not clear another. The test now covers this explicitly. We retain the copyable, non-owning token instead of adding global queue queries or making it an owning future. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
