Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi GSI update #170

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ pom.xml*
local-dynamo/
.clj-kondo/.cache
.#*
.idea
*.iml
5 changes: 3 additions & 2 deletions src/taoensso/faraday.clj
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,14 @@
[table table-desc {:keys [throughput gsindexes stream-spec billing-mode] :as params}]
(assert (not (and throughput
(= :pay-per-request billing-mode))) "Can't specify :throughput and :pay-per-request billing-mode")
(let [attr-defs (keydefs nil nil nil [gsindexes])]
(let [gsindexes (cond-> gsindexes (map? gsindexes) vector)
attr-defs (keydefs nil nil nil gsindexes)]
(doto-cond
[_ (UpdateTableRequest.)]
:always (.setTableName (name table))
throughput (.setProvisionedThroughput (provisioned-throughput throughput))
billing-mode (.setBillingMode (utils/enum billing-mode))
gsindexes (.setGlobalSecondaryIndexUpdates [(global-2nd-index-updates table-desc gsindexes)])
gsindexes (.setGlobalSecondaryIndexUpdates (mapv (partial global-2nd-index-updates table-desc) gsindexes))
stream-spec (.setStreamSpecification (stream-specification stream-spec))
(seq attr-defs) (.setAttributeDefinitions attr-defs))))

Expand Down
32 changes: 11 additions & 21 deletions test/taoensso/faraday/tests/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1070,18 +1070,16 @@
}})
;; We need to wait until the index is created before updating it, or the call will fail
_ @(index-status-watch *client-opts* temp-table :gsindexes "genre-index")
inc-idx @(far/update-table *client-opts* temp-table
{:gsindexes {:operation :update
:name "genre-index"
:throughput {:read 6 :write 6}
}})
;; We can create a second index right after
amt-idx @(far/update-table *client-opts* temp-table
{:gsindexes {:operation :create
:name "amount-index"
:hash-keydef [:amount :n]
:throughput {:read 1 :write 1}
}})
inc-and-amt-idxs @(far/update-table *client-opts* temp-table
{:gsindexes [{:operation :update
:name "genre-index"
:throughput {:read 6 :write 6}
}
{:operation :create
:name "amount-index"
:hash-keydef [:amount :n]
:throughput {:read 1 :write 1}
}]})
;; Let's wait until amount-index is created before deleting genre-index,
;; so that we can consistently evaluate the result (otherwise we might not
;; know if size/item-count are 0 or nil.
Expand All @@ -1103,14 +1101,6 @@
:throughput {:read 4 :write 2 :last-decrease nil :last-increase nil :num-decreases-today nil}}]
(->> (:gsindexes new-idx) (map #(dissoc % :size :item-count))))))
(testing "The updated index has the new throughput values, as well as a size and item-count since it was already created"
(is (= [{:name :genre-index
:size 0
:item-count 0
:key-schema [{:name :genre :type :hash}]
:projection {:projection-type "ALL" :non-key-attributes nil}
:throughput {:read 6 :write 6 :last-decrease nil :last-increase nil :num-decreases-today nil}}]
(:gsindexes inc-idx))))
(testing "The second index created comes back"
(is (= #{{:name :amount-index
:key-schema [{:name :amount :type :hash}]
:projection {:projection-type "ALL" :non-key-attributes nil}
Expand All @@ -1119,7 +1109,7 @@
:key-schema [{:name :genre :type :hash}]
:projection {:projection-type "ALL" :non-key-attributes nil}
:throughput {:read 6 :write 6 :last-decrease nil :last-increase nil :num-decreases-today nil}}}
(set (->> (:gsindexes amt-idx) (map #(dissoc % :size :item-count)))))))
(set (->> (:gsindexes inc-and-amt-idxs) (map #(dissoc % :size :item-count)))))))
(testing "When we request that the genre index be deleted, it returns that it's being destroyed"
(is (= #{{:name :amount-index
:key-schema [{:name :amount :type :hash}]
Expand Down