From 7743828d4f30b57ee251ce3e4ae347ebdbb6ca37 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 28 Nov 2018 12:27:25 +0000 Subject: Validate chunk size when persist --- app/models/ci/build_trace_chunk.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'app/models/ci/build_trace_chunk.rb') diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index 7c84bd734bb..da08214963f 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -15,6 +15,8 @@ module Ci WRITE_LOCK_SLEEP = 0.01.seconds WRITE_LOCK_TTL = 1.minute + FailedToPersistDataError = Class.new(StandardError) + # Note: The ordering of this enum is related to the precedence of persist store. # The bottom item takes the higest precedence, and the top item takes the lowest precedence. enum data_store: { @@ -109,16 +111,19 @@ module Ci def unsafe_persist_to!(new_store) return if data_store == new_store.to_s - raise ArgumentError, 'Can not persist empty data' unless size > 0 - old_store_class = self.class.get_store_class(data_store) + current_data = get_data - get_data.tap do |the_data| - self.raw_data = nil - self.data_store = new_store - unsafe_set_data!(the_data) + unless current_data&.bytesize.to_i == CHUNK_SIZE + raise FailedToPersistDataError, 'Data is not fullfilled in a bucket' end + old_store_class = self.class.get_store_class(data_store) + + self.raw_data = nil + self.data_store = new_store + unsafe_set_data!(current_data) + old_store_class.delete_data(self) end -- cgit v1.2.3