diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-06-25 16:19:40 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-25 16:19:40 +0900 |
commit | 24ba0989878a363c37d86758844a17a99fc7ae0c (patch) | |
tree | 6599adaf40d7d8bec14fee9c9fa03de7862ad7f8 /app | |
parent | 494673793d6b4491b2a7843f0614e5bcb3d88a3c (diff) | |
download | gitlab-ce-24ba0989878a363c37d86758844a17a99fc7ae0c.tar.gz |
Added spec for build trace chunk
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build_trace_chunk.rb | 21 | ||||
-rw-r--r-- | app/services/concerns/exclusive_lease_lock.rb | 4 |
2 files changed, 14 insertions, 11 deletions
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index 59096f54f0b..8a34db798db 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -8,8 +8,6 @@ module Ci default_value_for :data_store, :redis - WriteError = Class.new(StandardError) - CHUNK_SIZE = 128.kilobytes WRITE_LOCK_RETRY = 10 WRITE_LOCK_SLEEP = 0.01.seconds @@ -65,6 +63,7 @@ module Ci end def truncate(offset = 0) + raise ArgumentError, 'Fog store does not support truncating' if fog? # If data is null, get_data returns Excon::Error::NotFound raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0 return if offset == size # Skip the following process as it doesn't affect anything @@ -72,6 +71,8 @@ module Ci end def append(new_data, offset) + raise ArgumentError, 'Fog store does not support appending' if fog? # If data is null, get_data returns Excon::Error::NotFound + raise ArgumentError, 'New data is nil' unless new_data raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0 raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize) @@ -98,21 +99,17 @@ module Ci (start_offset...end_offset) end - def data_persisted? - !redis? - end - def persist_data! in_lock(*lock_params) do # Write opetation is atomic - unsafe_migrate_to!(self.class.persist_store) + unsafe_persist_to!(self.class.persist_store) end end private - def unsafe_migrate_to!(new_store) + def unsafe_persist_to!(new_store) return if data_store == new_store.to_s - return unless size > 0 + raise ArgumentError, 'Can not persist empty data' unless size > 0 old_store_class = self.class.get_store_class(data_store) @@ -130,7 +127,7 @@ module Ci end def unsafe_set_data!(value) - raise ArgumentError, 'too much data' if value.bytesize > CHUNK_SIZE + raise ArgumentError, 'New data size exceeds chunk size' if value.bytesize > CHUNK_SIZE self.class.get_store_class(data_store).set_data(self, value) @data = value @@ -144,6 +141,10 @@ module Ci Ci::BuildTraceChunkFlushWorker.perform_async(id) end + def data_persisted? + !redis? + end + def full? size == CHUNK_SIZE end diff --git a/app/services/concerns/exclusive_lease_lock.rb b/app/services/concerns/exclusive_lease_lock.rb index 6c8bc25ea16..231cfd3e3c5 100644 --- a/app/services/concerns/exclusive_lease_lock.rb +++ b/app/services/concerns/exclusive_lease_lock.rb @@ -1,6 +1,8 @@ module ExclusiveLeaseLock extend ActiveSupport::Concern + FailedToObtainLockError = Class.new(StandardError) + def in_lock(key, ttl: 1.minute, retry_max: 10, sleep_sec: 0.01.seconds) lease = Gitlab::ExclusiveLease.new(key, timeout: ttl) retry_count = 0 @@ -12,7 +14,7 @@ module ExclusiveLeaseLock break if retry_max < (retry_count += 1) end - raise WriteError, 'Failed to obtain write lock' unless uuid + raise FailedToObtainLockError, 'Failed to obtain a lock' unless uuid return yield ensure |