this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Track total bytes written by block store

garrison 5c77bac1 c1eb3906

+48
+19
lib/xks/blocks.ex
··· 6 6 7 7 @hash_function :sha256 8 8 9 + @spec get_bytes_written(XKS.block_store) :: non_neg_integer 10 + def get_bytes_written(store) do 11 + do_get_bytes_written(store) 12 + end 13 + 14 + defp do_get_bytes_written({:memory, memory_store}) do 15 + MemoryStore.get_bytes_written(memory_store) 16 + end 17 + 18 + defp do_get_bytes_written({:file, file_store}) do 19 + FileStore.get_bytes_written(file_store) 20 + end 21 + 9 22 @spec write_superblock(XKS.block_store, non_neg_integer, binary) :: :ok 10 23 def write_superblock(store, copy, block_data) do 11 24 do_write_superblock(store, copy, block_data) 12 25 end 13 26 14 27 defp do_write_superblock({:memory, memory_store}, copy, block_data) do 28 + MemoryStore.inc_bytes_written(memory_store, byte_size(block_data)) 15 29 MemoryStore.put_superblock(memory_store, copy, block_data) 16 30 end 17 31 18 32 defp do_write_superblock({:file, file_store}, copy, block_data) do 33 + :ok = FileStore.inc_bytes_written(file_store, byte_size(block_data)) 19 34 FileStore.put_superblock(file_store, copy, block_data) 20 35 end 21 36 ··· 50 65 51 66 defp do_write({:memory, memory_store}, index, block_data) do 52 67 assert byte_size(block_data) == MemoryStore.get_block_size(memory_store) 68 + MemoryStore.inc_bytes_written(memory_store, byte_size(block_data)) 53 69 MemoryStore.put(memory_store, index, block_data) 54 70 end 55 71 56 72 defp do_write({:file, file_store}, index, block_data) do 73 + :ok = FileStore.inc_bytes_written(file_store, byte_size(block_data)) 57 74 FileStore.put(file_store, index, block_data) 58 75 end 59 76 ··· 120 137 end 121 138 assert byte_size(existing) == position 122 139 140 + MemoryStore.inc_bytes_written(memory_store, byte_size(data)) 123 141 MemoryStore.put(memory_store, extent_index, existing <> data) 124 142 end 125 143 126 144 defp do_write_extent({:file, file_store}, extent_index, position, data) do 145 + :ok = FileStore.inc_bytes_written(file_store, byte_size(data)) 127 146 FileStore.put_extent(file_store, extent_index, position, data) 128 147 end 129 148
+14
lib/xks/file_store.ex
··· 9 9 @type t :: %__MODULE__{ 10 10 path: binary, 11 11 fd: term, 12 + bytes_written_atomic: :atomics.atomics_ref, 12 13 block_size: pos_integer, 13 14 } 14 15 @enforce_keys [ 15 16 :path, 16 17 :fd, 18 + :bytes_written_atomic, 17 19 :block_size, 18 20 ] 19 21 defstruct @enforce_keys ··· 32 34 %FileStore{ 33 35 path: path, 34 36 fd: fd, 37 + bytes_written_atomic: :atomics.new(1, signed: false), 35 38 block_size: block_size, 36 39 } 37 40 end ··· 46 49 def destroy(%FileStore{} = _file_store) do 47 50 # TODO: delete file 48 51 :ok 52 + end 53 + 54 + @spec inc_bytes_written(t, non_neg_integer) :: :ok 55 + def inc_bytes_written(%FileStore{bytes_written_atomic: bw_atomic} = _file_store, bytes) 56 + when is_integer(bytes) and bytes >= 0 do 57 + :atomics.add(bw_atomic, 1, bytes) 58 + end 59 + 60 + @spec get_bytes_written(t) :: non_neg_integer 61 + def get_bytes_written(%FileStore{bytes_written_atomic: bw_atomic} = _file_store) do 62 + :atomics.get(bw_atomic, 1) 49 63 end 50 64 51 65 @spec put_superblock(t, non_neg_integer, binary) :: :ok
+2
lib/xks/fuzz/write_info.ex
··· 42 42 43 43 max_block = XKS.FreeList.get_max_block(xks.free_list) 44 44 xks_size_bytes = xks.opts.block_size * max_block 45 + total_bytes_written = XKS.Blocks.get_bytes_written(xks.block_store) 45 46 46 47 dbg state.bytes_written / 1_000_000 47 48 dbg xks_size_bytes / 1_000_000 49 + dbg total_bytes_written / 1_000_000 48 50 dbg XKS.FreeList.get_free_blocks_count(xks.free_list) 49 51 #dbg XKS.Manifest.dump(xks.manifest), limit: :infinity 50 52
+13
lib/xks/memory_store.ex
··· 5 5 def new(block_size) when is_integer(block_size) do 6 6 store = :ets.new(__MODULE__, [:set, :public]) 7 7 :ets.insert(store, {:block_size, block_size}) 8 + :ets.insert(store, {:bytes_written, 0}) 8 9 9 10 store 10 11 end ··· 13 14 def destroy(store) do 14 15 :ets.delete(store) 15 16 :ok 17 + end 18 + 19 + @spec inc_bytes_written(t, non_neg_integer) :: :ok 20 + def inc_bytes_written(store, bytes) when is_integer(bytes) and bytes >= 0 do 21 + :ets.update_counter(store, :bytes_written, bytes) 22 + :ok 23 + end 24 + 25 + @spec get_bytes_written(t) :: non_neg_integer 26 + def get_bytes_written(store) do 27 + [{:bytes_written, bytes_written}] = :ets.lookup(store, :bytes_written) 28 + bytes_written 16 29 end 17 30 18 31 @spec get_block_size(t) :: pos_integer