Skip to content

INTERNAL: Make a lane job from each item event of the engine - #21

Merged
jhpark816 merged 1 commit into
developfrom
event-callback
Nov 12, 2026
Merged

jhpark816 merged 1 commit into
developfrom
event-callback

Conversation

@ing-eoking

Copy link
Copy Markdown
Collaborator

🔗 Related Issue

⌨️ What I did

엔진의 item 이벤트 콜백(ON_EVENT_ITEM)을 등록하고, element 이벤트가 오면 그 자리에서 Job을 만들어 Pool에 넘깁니다.

클라이언트 쓰기뿐 아니라 복제·persistence 재생으로 바뀐 element도 같은 콜백으로 들어옵니다.
그래서 Job을 명령에서 미리 만들지 않고 콜백에서 이벤트를 보고 만듭니다.
이렇게 하면 세 경로가 하나의 코드로 처리됩니다.

흐름

쓰기 명령 (execute)
  event::offer(엔진 내부)       // 엔진에서 Connection을 넘겨 받기 위해 스레드 로컬
    └ 이벤트 콜백 (같은 스레드, 동기)
        op = 이벤트에서 생성 (Map 키 → index, element 주소 → elem)
        aio::begin(op, CONN.take())       // 연결이 있으면 wait_for_io + on_io_complete 등록
  이벤트가 오지 않으면(쓰기 실패 등) 연결을 돌려받아 명령이 직접 응답
----------------------------------------------------------------------------------------
복제·재생
  이벤트 콜백 → aio::begin(op, None)      // 응답할 연결 없이 Pool에서 처리만 함

검색 (execute)
  aio::begin(op, Some(conn))
  • 엔진은 이벤트 콜백에 cookie를 NULL로 넘깁니다. 그래서 어느 연결의 쓰기인지는 스레드 로컬로 전달합니다.
    콜백은 엔진 쓰기 안에서 같은 스레드로 동기 호출되므로 스레드 로컬로 충분합니다.
  • offer는 클로저 범위 안에서만 연결을 스레드 로컬에 둡니다.
    패닉이 나도 끝나면 비우기 때문에, execute가 끝난 연결이 남아 다른 이벤트에서 쓰이는 일이 없습니다.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ing-eoking
ing-eoking changed the base branch from main to precheck November 4, 2026 01:27
@ing-eoking
ing-eoking changed the base branch from precheck to quant November 4, 2026 01:27
@ing-eoking ing-eoking changed the title Event callback INTERNAL: Make a lane job from each item event of the engine Nov 4, 2026
@ing-eoking
ing-eoking force-pushed the event-callback branch 3 times, most recently from fc163da to 26ed023 Compare November 4, 2026 14:08
@ing-eoking
ing-eoking force-pushed the event-callback branch 2 times, most recently from 14ae5e8 to 3800918 Compare November 5, 2026 01:06
@ing-eoking
ing-eoking force-pushed the event-callback branch 2 times, most recently from d2238e3 to f2743b4 Compare November 5, 2026 14:10
@ing-eoking
ing-eoking force-pushed the quant branch 2 times, most recently from efc25de to 624cddb Compare November 5, 2026 15:15
@ing-eoking
ing-eoking force-pushed the event-callback branch 3 times, most recently from 87ff2f3 to cec7eb1 Compare November 6, 2026 00:05
@ing-eoking
ing-eoking force-pushed the quant branch 2 times, most recently from 458268f to 746c76b Compare November 6, 2026 01:19
@ing-eoking
ing-eoking marked this pull request as draft November 6, 2026 03:13
@ing-eoking
ing-eoking force-pushed the quant branch 2 times, most recently from 4d7a776 to c2010cf Compare November 9, 2026 00:15
@ing-eoking
ing-eoking force-pushed the event-callback branch 2 times, most recently from 8cc9d23 to be7b816 Compare November 9, 2026 02:38
@zhy2on

zhy2on commented Nov 9, 2026

Copy link
Copy Markdown
Member

쓰기 명령 처리 중에 만료나 evict로 ITEM_UNLINK/ELEM_DELETE 콜백이 불리면 그 명령의 응답 대신 Drop/Delete op의 응답이 가는 문제는 없을까요?
지난번에 관련해서 들은 것 같기도 한데, 기억이 나지 않아 댓글 남깁니다.

@ing-eoking

Copy link
Copy Markdown
Collaborator Author

@zhy2on

Replication/Persistence, Eviction, Expire에 의해 발생하는 쓰기 작업은 사용자가 직접 vop 명령어를 실행한 경우가 아니므로,
쓰레드 로컬 변수인 CONN(현재 요청을 보낸 커넥션 주소)이 None으로 설정됩니다.

이 경우 이벤트는 Reply와 Waiter를 모두 None으로 설정하여 작업을 전달하며,
Lane에서는 작업을 완료한 후 별도의 응답을 반환하지 않습니다.

@zhy2on

zhy2on commented Nov 9, 2026

Copy link
Copy Markdown
Member

@ing-eoking
사용자가 보낸 vop 명령을 처리하던 도중 do_item_mem_alloc에서 evict가 일어나거나,
만료된 키에 처음 접근하는 경우에는 CONN이 설정된 상태일 것 같은데 이런 경우는 발생하지 않는 걸까요?

@ing-eoking

Copy link
Copy Markdown
Collaborator Author

@zhy2on

무슨 말인지 이해했습니다. 현재 그 처리가 없습니다.

아마 이 문제 때문에 원래는 엔진을 호출하기 전에 Task를 미리 만들어 두고, 이벤트에서는 필요한 부분만 채워 넘기는 방식이었던 것 같습니다. 그런데 Job 타입을 제거하면서 이 부분이 불필요하다고 판단해 함께 지워버린 것 같습니다. 이전과 같은 방식으로 다시 구현하면 될 것 같습니다.

execute 이후 Arcus Vector에서 Op(Lane에서 처리할 작업 종류)와 Reply(응답을 담을 메모리 공간) 등을 미리 준비해 두고, 이벤트 콜백에서 나머지 부분을 채워 Lane으로 넘깁니다. 이때 Op와 이벤트 콜백 타입이 일치하지 않으면 Reply 등은 채우지 않고 넘깁니다.

@zhy2on zhy2on left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경사항 확인했습니다. 수고하셨습니다

Comment thread src/aio.rs Resolved
@ing-eoking
ing-eoking requested a review from jhpark816 November 12, 2026 00:51
@jhpark816
jhpark816 merged commit 2d25619 into develop Nov 12, 2026
4 checks passed
@ing-eoking
ing-eoking deleted the event-callback branch November 12, 2026 01:31

This branch was successfully deployed

1 active deployment
ee — 0923a6d2 Deployed Nov 12, 2026 by ing-eoking via Build arcus-memcached #84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants