Skip to content

Commit

Permalink
v1.16: geyser: use Ordering::Relaxed instead of SeqCst (backport of #221
Browse files Browse the repository at this point in the history
) (#222)

(cherry picked from commit f88fd64)

Co-authored-by: Kirill Fomichev <[email protected]>
  • Loading branch information
mergify[bot] and fanatid authored Oct 27, 2023
1 parent 60fd038 commit 94f2330
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The minor version will be incremented upon a breaking change and the patch versi

- geyser: trigger end of startup when parent slot 0 seen in `update_slot_status` notification because `notify_end_of_startup` is not triggered when cluster started from genesis ([#207](https://github.com/rpcpool/yellowstone-grpc/pull/207))
- tools: correctly handle SIGINT in kafka ([#219](https://github.com/rpcpool/yellowstone-grpc/pull/219))
- geyser: use Ordering::Relaxed instead of SeqCst ([#221](https://github.com/rpcpool/yellowstone-grpc/pull/221))

### Features

Expand Down
2 changes: 1 addition & 1 deletion yellowstone-grpc-geyser/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ impl Geyser for GrpcService {
&self,
mut request: Request<Streaming<SubscribeRequest>>,
) -> TonicResult<Response<Self::SubscribeStream>> {
let id = self.subscribe_id.fetch_add(1, Ordering::SeqCst);
let id = self.subscribe_id.fetch_add(1, Ordering::Relaxed);
let filter = Filter::new(
&SubscribeRequest {
accounts: HashMap::new(),
Expand Down
25 changes: 13 additions & 12 deletions yellowstone-grpc-geyser/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Plugin {
{
// Full block reconstruction will fail before first processed slot received
let inner = self.inner.as_ref().expect("initialized");
if inner.startup_status.load(Ordering::SeqCst)
if inner.startup_status.load(Ordering::Relaxed)
== STARTUP_END_OF_RECEIVED | STARTUP_PROCESSED_RECEIVED
{
f(inner)
Expand Down Expand Up @@ -153,17 +153,17 @@ impl GeyserPlugin for Plugin {
fn notify_end_of_startup(&self) -> PluginResult<()> {
let inner = self.inner.as_ref().expect("initialized");

inner
.startup_status
.fetch_or(STARTUP_END_OF_RECEIVED, Ordering::Relaxed);

if let Some(channel) = &inner.snapshot_channel {
match channel.send(None) {
Ok(()) => MESSAGE_QUEUE_SIZE.inc(),
Err(_) => panic!("failed to send message to startup queue: channel closed"),
}
}

inner
.startup_status
.fetch_or(STARTUP_END_OF_RECEIVED, Ordering::SeqCst);

Ok(())
}

Expand All @@ -179,14 +179,15 @@ impl GeyserPlugin for Plugin {
if parent == Some(0) {
inner
.startup_status
.fetch_or(STARTUP_END_OF_RECEIVED, Ordering::SeqCst);
.fetch_or(STARTUP_END_OF_RECEIVED, Ordering::Relaxed);
}
if inner.startup_status.load(Ordering::SeqCst) == STARTUP_END_OF_RECEIVED
&& status == SlotStatus::Processed
{
inner
.startup_status
.fetch_or(STARTUP_PROCESSED_RECEIVED, Ordering::SeqCst);
if status == SlotStatus::Processed {
let _ = inner.startup_status.compare_exchange(
STARTUP_END_OF_RECEIVED,
STARTUP_END_OF_RECEIVED | STARTUP_PROCESSED_RECEIVED,
Ordering::Relaxed,
Ordering::Relaxed,
);
}

self.with_inner(|inner| {
Expand Down
2 changes: 1 addition & 1 deletion yellowstone-grpc-tools/src/kafka/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Geyser for GrpcService {
&self,
mut request: Request<Streaming<SubscribeRequest>>,
) -> TonicResult<Response<Self::SubscribeStream>> {
let id = self.subscribe_id.fetch_add(1, Ordering::SeqCst);
let id = self.subscribe_id.fetch_add(1, Ordering::Relaxed);
let (stream_tx, stream_rx) = mpsc::channel(self.channel_capacity);
let notify_client = Arc::new(Notify::new());
let notify_exit1 = Arc::new(Notify::new());
Expand Down

0 comments on commit 94f2330

Please sign in to comment.