You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "yjhjstz (via GitHub)" <gi...@apache.org> on 2025/07/11 21:36:41 UTC

[PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

yjhjstz opened a new pull request, #1225:
URL: https://github.com/apache/cloudberry/pull/1225

   
   The legacy event_init() function is not thread-safe and can cause issues when gpfdist is run in multi-threaded environments. This patch updates gpfdist to use libevent 2.0+'s thread-safe APIs, specifically `event_base` along with `event_assign()` and `evtimer_assign()`.
   
   A new global `gcb.event_base` is introduced and used when compiled with libevent ≥ 2.0.1. This avoids the need for the deprecated and non-thread-safe `event_set()` / `evtimer_set()` APIs, and prepares gpfdist for better thread safety.
   
   This change maintains backward compatibility with older libevent versions via conditional compilation.
   
   
   Fixes #ISSUE_Number
   
   ### What does this PR do?
   <!-- Brief overview of the changes, including any major features or fixes -->
   
   ### Type of Change
   - [ ] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   <!-- Remove if not applicable. If yes, explain impact and migration path -->
   
   ### Test Plan
   <!-- How did you test these changes? -->
   - [ ] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   ### Impact
   <!-- Remove sections that don't apply -->
   **Performance:**
   <!-- Any performance implications? -->
   
   **User-facing changes:**
   <!-- Any changes visible to users? -->
   
   **Dependencies:**
   <!-- New dependencies or version changes? -->
   
   ### Checklist
   - [ ] Followed [contribution guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [ ] Reviewed code for security implications
   - [ ] Requested review from [cloudberry committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   <!-- Any other information that would help reviewers? Remove if none -->
   
   ### CI Skip Instructions
   <!--
   To skip CI builds, add the appropriate CI skip identifier to your PR title.
   The identifier must:
   - Be in square brackets []
   - Include the word "ci" and either "skip" or "no"
   - Only use for documentation-only changes or when absolutely necessary
   -->
   
   ---
   <!-- Join our community:
   - Mailing list: [dev@cloudberry.apache.org](https://lists.apache.org/list.html?dev@cloudberry.apache.org) (subscribe: dev-subscribe@cloudberry.apache.org)
   - Discussions: https://github.com/apache/cloudberry/discussions -->
   


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "my-ship-it (via GitHub)" <gi...@apache.org>.
my-ship-it commented on PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#issuecomment-3112237526

   Good start. Do we plan to enable multi-threads for libevent 2.0+ in current PR?


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "gfphoenix78 (via GitHub)" <gi...@apache.org>.
gfphoenix78 commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2228160152


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -1600,7 +1603,11 @@ static void session_detach(request_t* r)
 			}
 
 			event_del(&session->ev);
+#if defined(EVENT__VERSION) && EVENT__NUMERIC_VERSION >= 0x02000100
+			evtimer_assign(&session->ev, gcb.event_base, free_session_cb, session);
+#else
 			evtimer_set(&session->ev, free_session_cb, session);
+#endif

Review Comment:
   The version of libevent on centos 7 is 2.0.21
   `libevent-2.0.21-4.el7.x86_64`
   
   It's quite an old version.



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "gfphoenix78 (via GitHub)" <gi...@apache.org>.
gfphoenix78 commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2228160152


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -1600,7 +1603,11 @@ static void session_detach(request_t* r)
 			}
 
 			event_del(&session->ev);
+#if defined(EVENT__VERSION) && EVENT__NUMERIC_VERSION >= 0x02000100
+			evtimer_assign(&session->ev, gcb.event_base, free_session_cb, session);
+#else
 			evtimer_set(&session->ev, free_session_cb, session);
+#endif

Review Comment:
   The version of libevent on centos 7 is 2.0.21
   `libevent-2.0.21-4.el7.x86_64`
   
   It's  a quite old version.



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2237994520


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -1600,7 +1603,11 @@ static void session_detach(request_t* r)
 			}
 
 			event_del(&session->ev);
+#if defined(EVENT__VERSION) && EVENT__NUMERIC_VERSION >= 0x02000100
+			evtimer_assign(&session->ev, gcb.event_base, free_session_cb, session);
+#else
 			evtimer_set(&session->ev, free_session_cb, session);
+#endif

Review Comment:
   done, and add configure check.



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "my-ship-it (via GitHub)" <gi...@apache.org>.
my-ship-it commented on PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#issuecomment-3130273346

   > > Good start. Do we plan to enable multi-threads for libevent 2.0+ in current PR?
   > 
   > No, simple multi threads mvp show performance downgrade.
   
   So do we still need the PR?


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2212003396


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -1600,7 +1603,11 @@ static void session_detach(request_t* r)
 			}
 
 			event_del(&session->ev);
+#if defined(EVENT__VERSION) && EVENT__NUMERIC_VERSION >= 0x02000100
+			evtimer_assign(&session->ev, gcb.event_base, free_session_cb, session);
+#else
 			evtimer_set(&session->ev, free_session_cb, session);
+#endif

Review Comment:
   thread safe api need libevent 2.0+.  since we are not sure about that.



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#issuecomment-3130291836

   
   > So do we still need the PR?
   
   yes, using thread-safe APIs is a better choice. In case we found the right way.
   
   
   


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#issuecomment-3113605402

   > Good start. Do we plan to enable multi-threads for libevent 2.0+ in current PR?
   
   No, simple mvp show performance downgrade. 


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "gfphoenix78 (via GitHub)" <gi...@apache.org>.
gfphoenix78 commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2212001349


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -1600,7 +1603,11 @@ static void session_detach(request_t* r)
 			}
 
 			event_del(&session->ev);
+#if defined(EVENT__VERSION) && EVENT__NUMERIC_VERSION >= 0x02000100
+			evtimer_assign(&session->ev, gcb.event_base, free_session_cb, session);
+#else
 			evtimer_set(&session->ev, free_session_cb, session);
+#endif

Review Comment:
   Why not to remove the thread-unsafe code?



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz merged PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225


-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] [gpfdist] Use event_base with libevent 2.0+ to avoid thread-unsafe event_init [cloudberry]

Posted by "gfphoenix78 (via GitHub)" <gi...@apache.org>.
gfphoenix78 commented on code in PR #1225:
URL: https://github.com/apache/cloudberry/pull/1225#discussion_r2244136508


##########
src/bin/gpfdist/gpfdist.c:
##########
@@ -233,6 +233,7 @@ static struct
 	SSL_CTX 		*server_ctx;/* for SSL */
 #endif
 	int 			wdtimer; /* Kill gpfdist after k seconds of inactivity. 0 to disable. */
+	struct event_base *event_base; /* for libevent 2.0+ */
 } gcb;

Review Comment:
   Is it reasonable to use the static variable gcb for thread-safe?



-- 
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: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org