Repository navigation
使えるバッファ数から演算子が取るバッファ数を決める BufferNeeds を入れる - #37
Merged
Merged
Conversation
マルチバッファのソートや積が、使えるバッファ数から何バッファ使うかを決めるため。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inned マルチバッファの演算子はトランザクションしか持たないため、そこから空き数を聞けるようにする。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… many are free マルチバッファのソートは根、積は約数でチャンクの大きさを決めるため、その計算を共通にしておく。 根は浮動小数の誤差で 1 多くなることがあるので、整数で求める。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
14 章 Effective Buffer Utilization の最初の段として、空いているバッファの数を聞く手段と、その数から演算子が何バッファ取るかを決める計算を追加した。SimpleDB の
BufferMgr.available/Transaction.availableBuffsと、BufferNeeds.bestRoot/bestFactorに相当する。この後のマルチバッファ積(チャンクの大きさに
BestFactorを使う)と、マルチバッファソート(run の大きさとマージの本数にBestRootを使う)の土台になる。この PR ではまだどの演算子からも使わない。buffer_managerBufferManager.Available:ピンされていないバッファの数を返すtransactionTransaction.AvailableBuffers:Availableに委譲する。演算子はトランザクションしか持たないためmultibuffer(新しいパッケージ)BestRoot:size、その平方根、立方根…(切り上げ)のうち、空きに収まる最初のものBestFactor:size、size/2、size/3…(切り上げ)のうち、空きに収まる最初のもの設計上の判断
BestRootは、size がそのまま空きに収まるなら size を返す。 SimpleDB のbestRootはループの初回で必ず平方根に進むので、たとえば空き 10・size 4 でも 2 を返す。本文の「空きに収まる最大の根」に合わせ、1 乗根から試すようにした。ソートでは、入力全体を 1 本の run としてメモリ上で扱えることになる。math.Pow(size, 1/i)の切り上げは、浮動小数の誤差で 1 多くなることがある(math.Pow(125, 1/3.0)は5.000000000000001なので 6 になる)。math.Powは最初の見当にだけ使い、「k^i ≥ sizeを満たす最小の k」に整数で寄せる。k^iは size に届いた時点で掛け算を打ち切るので、桁あふれしない。既知の制限
Availableの値は聞いた時点のもの。プールは全トランザクションで共有しているので、聞いた後に他のトランザクションが取ることがある。その場合ピンは待たされ、最悪ErrBufferAbortになる。SimpleDB も同じ。テスト
BufferManager.Available:何もピンしていない、異なる 2 ブロックをピン、同じブロックを 2 回ピン(1 バッファしか使わない)、ピンを 1 つ外すTransaction.AvailableBuffers:自分がピンした分、別のトランザクションがピンした分(プールが共有であること)BestRoot:予約を引くと 1 以下、size がそのまま収まる、平方根の切り上げ、ちょうど収まる境界(64 → 8)、立方根(1000 → 10)、立方根の切り上げが収まらず 4 乗根へ(1001 → 6)、浮動小数だと 1 多くなる(125 → 5)、size 0BestFactor:予約を引くと 1 以下、size がそのまま収まる、半分、ちょうど収まる境界(20 → 5)、切り上げが収まらず次へ(21 → 4)、size 0golangci-lintは手元に入っていないため、ローカルでは実行していない🤖 Generated with Claude Code