Skip to content

Commit

Permalink
multi gsi
Browse files Browse the repository at this point in the history
  • Loading branch information
WBSemple committed May 10, 2024
1 parent 9be71cb commit b042dfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
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

0 comments on commit b042dfa

Please sign in to comment.