u70b3 commented on code in PR #203:
URL: https://github.com/apache/paimon-cpp/pull/203#discussion_r3781895295
##########
src/paimon/common/factories/io_hook.cpp:
##########
@@ -49,9 +49,11 @@ class IOHook::Impl {
}
inline void Reset(int64_t pos, IOHook::Mode mode) {
+ // Store mode_ first: the seq_cst stores below then publish it, so a
Try()
+ // that observes the reset pos_ also observes the new mode_.
+ mode_.store(mode, std::memory_order_relaxed);
Review Comment:
Good catch. I now synchronize the complete IOHook configuration with a
shared mutex and updated the regression test to assert that concurrent Clear()
/ Reset(INT64_MAX, RETURN_ERROR) never returns an error.
##########
src/paimon/common/utils/saturating_cast.h:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 <cmath>
+#include <limits>
+#include <type_traits>
+
+namespace paimon {
+
+/// Converts a double to a signed integral type with the saturation policy
docs/code-style.md
+/// requires (the one Java applies and
NumericPrimitiveCastExecutor::JavaFloatingToIntegerCast
+/// implements in core/): NaN converts to 0 and an out-of-range value
saturates at the bounds
+/// of TargetType. A bare static_cast of an unrepresentable double is
undefined behavior and
+/// diverges across architectures (x86 cvttsd2si yields the "integer
indefinite" value, aarch64
+/// fcvtzs saturates), so doubles that are not provably in range must go
through this helper.
+template <typename TargetType>
+inline TargetType SaturatingDoubleToInteger(double value) {
+ static_assert(std::is_integral_v<TargetType> &&
std::is_signed_v<TargetType>,
Review Comment:
Agreed. I restricted the helper to the intended int32_t and int64_t targets
and clarified that narrower Java conversions require a separate narrowing step.
--
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]