Skip to content

Commit

Permalink
fixed parameter passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula Gearon committed Sep 30, 2020
1 parent b4ae851 commit 3b065ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/asami/durable/block/bufferblock.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
;; An implementation of Block that can have multiple readers,
;; but only a single writing thread
(defrecord BufferBlock
[^ByteBuffer bb ^IntBuffer ib ^LongBuffer lb
[id
^ByteBuffer bb ^IntBuffer ib ^LongBuffer lb
^ByteBuffer ro
size
byte-offset int-offset long-offset]

Block
(get-id [this] id)

(get-byte [this offset]
(.get bb (+ byte-offset offset)))

Expand Down Expand Up @@ -100,21 +104,21 @@
(defn- new-block
"Internal implementation for creating a BufferBlock using a set of buffers.
If lb is nil, then ib must also be nil"
[bb ib lb ro byte-offset]
[id bb ib lb ro size byte-offset]
(assert (or (and ib lb) (not (or ib lb))) "int and long buffers must be provided or excluded together")
(let [ib (or ib (-> bb .rewind .asIntBuffer))
lb (or lb (-> bb .asLongBuffer))
ro (or ro (.asReadOnlyBuffer bb))
int-offset (bit-shift-right byte-offset 2)
long-offset (bit-shift-right byte-offset 3)]
(->BufferBlock bb ib lb ro byte-offset int-offset long-offset)))
(->BufferBlock id bb ib lb ro size byte-offset int-offset long-offset)))

(defn ^BufferBlock create-block
"Wraps provided buffers as a block"
([size byte-offset byte-buffer ro-byte-buffer int-buffer long-buffer]
(new-block byte-buffer int-buffer long-buffer ro-byte-buffer size byte-offset))
([size byte-offset byte-buffer]
(new-block byte-buffer nil nil nil size byte-offset)))
([id size byte-offset byte-buffer ro-byte-buffer int-buffer long-buffer]
(new-block id byte-buffer int-buffer long-buffer ro-byte-buffer size byte-offset))
([id size byte-offset byte-buffer]
(new-block id byte-buffer nil nil nil size byte-offset)))


;; The following functions are ByteBuffer specfic,
Expand Down
12 changes: 6 additions & 6 deletions test/asami/durable/block/test_blockfile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

(deftest test-allocate
(let [filename (util/temp-file "ualloc")
{:keys [block-file file]} (open-block-file filename test-block-size)]
(set-nr-blocks! block-file 1)
block-file (open-block-file filename test-block-size)
block-file (set-nr-blocks! block-file 1)]
(try
(let [blk (block-for block-file 0)]
(is (not (nil? blk))))
Expand All @@ -68,7 +68,7 @@
(deftest test-write
(let [file-str "bftest"
filename (util/temp-file file-str)
{:keys [block-file file]} (open-block-file filename test-block-size)
block-file (open-block-file filename test-block-size)
bf (set-nr-blocks! block-file 4)
b (block-for bf 0)
_ (put-string! b str0)
Expand All @@ -89,7 +89,7 @@
(unmap bf)
(cleanup)

(let [{:keys [block-file file]} (open-block-file filename test-block-size)]
(let [block-file (open-block-file filename test-block-size)]

;; did it persist

Expand All @@ -107,8 +107,8 @@
(deftest test-performance
(let [file-str "perftest"
filename (util/temp-file file-str)
{:keys [block-file file]} (open-block-file filename test-block-size)
_ (clear! block-file)
block-file (open-block-file filename test-block-size)
block-file (clear! block-file)
nr-blocks 100000
bf (set-nr-blocks! block-file nr-blocks)]

Expand Down

0 comments on commit 3b065ac

Please sign in to comment.