marcv81 commented on code in PR #11872:
URL: https://github.com/apache/inlong/pull/11872#discussion_r2102599737


##########
inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/util/id.go:
##########
@@ -29,12 +29,14 @@ var (
 )
 
 func init() {
+       var id uint32 = 0
+
+       // Generate the ID from an IP if possible.
        ip, err := GetOneIP()
-       if err != nil {
-               log.Fatal(err)

Review Comment:
   Thanks for the excellent suggestion @gunli. I updated the PR accordingly, 
but with some other modifications. Please let me know what you think :pray: 
   
   Instead of initialising the snowflake node in `init()`, we lazy-load it the 
first time we call `SnowFlakeID()`. The legacy behaviour of crashing in case of 
error remains, although the crash is deferred. Maintaining the legacy behaviour 
is helpful because we don't know how the SDK users might rely on it.
       
   Programs now also have the option to call `SafeFlakeID()` and handle the 
error instead of crashing. I did not modify the signature of `SnowFlakeID()` to 
maintain backward compatibility. I also propose to deprecate `SnowFlakeID()`.
   
   Testing (manual):
   - In a Docker container with no network, `SnowFlakeID()` crashes with the 
expected error message.
   - In a Docker container with no network, `SafeSnowFlakeID()` returns the 
expected error.
   - With network, `SnowFlakeID()` and `SafeSnowFlakeID()` both return an 
integer. I verified the integer remains the same every time I run the test (on 
the same machine).



-- 
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]

Reply via email to