You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm learning jepsen on postgres, and I notice a check rule in ledger.clj which confuses me.
`
(defn check-account
"Takes an [account, ops] tuple, and checks to make sure it has a non-negative
balance."
[[account ops]]
; When ops are indeterminate, we don't know if they took place or not. We
; have to take the most charitable interpretation: assume deposits succeed,
; withdrawals fail.
(let [deposits (filter (comp pos? second :value) ops)
withdrawals (filter (comp neg? second :value) ops)
balance (->> (concat deposits (filter op/ok? withdrawals))
(map (comp second :value))
(reduce + 0))]
(when (or (neg? balance) (pos? balance))
{:account account
:balance balance})))
`
This test is aimed at to check each banlance of the account is non-negative, why return result when banlance is pos?
`
(defn checker
[]
(reify checker/Checker
(check [_ test history opts]
(let [errs (->> history
(filter (comp #{:ok :info} :type))
(group-by (comp first :value))
(keep check-account))]
{:valid? (not (seq errs))
:errors errs}))))
`
this may lead to that it will be recognized as errors when checking, Am I reading this correctly?Thanks for your attention.
The text was updated successfully, but these errors were encountered:
Entirely possible this is wrong--just going through the namespace again, this looks like it may have been a work-in-progress I was sketching out but never finished.
I have no plans to revisit that particular code right now.On Nov 16, 2022 01:55, Dong ***@***.***> wrote:
ok, thanks for your reply! But is this ledger case will be finished?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
Hi, I'm learning jepsen on postgres, and I notice a check rule in ledger.clj which confuses me.
`
(defn check-account
"Takes an [account, ops] tuple, and checks to make sure it has a non-negative
balance."
[[account ops]]
; When ops are indeterminate, we don't know if they took place or not. We
; have to take the most charitable interpretation: assume deposits succeed,
; withdrawals fail.
(let [deposits (filter (comp pos? second :value) ops)
withdrawals (filter (comp neg? second :value) ops)
balance (->> (concat deposits (filter op/ok? withdrawals))
(map (comp second :value))
(reduce + 0))]
(when (or (neg? balance) (pos? balance))
{:account account
:balance balance})))
`
This test is aimed at to check each banlance of the account is non-negative, why return result when banlance is pos?
`
(defn checker
[]
(reify checker/Checker
(check [_ test history opts]
(let [errs (->> history
(filter (comp #{:ok :info} :type))
(group-by (comp first :value))
(keep check-account))]
{:valid? (not (seq errs))
:errors errs}))))
`
this may lead to that it will be recognized as errors when checking, Am I reading this correctly?Thanks for your attention.
The text was updated successfully, but these errors were encountered: