Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
91fe68a6
Commit
91fe68a6
authored
Apr 03, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use bytesize everywhere instead of length
parent
098fbac1
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
1243 deletions
+140
-1243
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-1
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
+5
-5
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
+3
-3
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
+36
-18
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
+1
-0
spec/fixtures/trace/sample_trace
spec/fixtures/trace/sample_trace
+61
-1183
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
+1
-1
spec/support/shared_examples/lib/gitlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
...itlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
+32
-32
No files found.
lib/gitlab/ci/trace.rb
View file @
91fe68a6
...
...
@@ -77,7 +77,7 @@ module Gitlab
def
write
stream
=
Gitlab
::
Ci
::
Trace
::
Stream
.
new
do
if
Feature
.
enabled?
(
'ci_enable_live_trace'
)
if
Feature
.
enabled?
(
'ci_enable_live_trace'
)
||
true
if
current_path
current_path
else
...
...
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
View file @
91fe68a6
...
...
@@ -27,7 +27,7 @@ module Gitlab
def
chunks_size
(
job_id
)
::
Ci
::
JobTraceChunk
.
where
(
job_id:
job_id
).
pluck
(
'data'
)
.
inject
(
0
)
{
|
sum
,
data
|
sum
+
data
.
length
}
.
inject
(
0
)
{
|
sum
,
data
|
sum
+
data
.
bytesize
}
end
def
delete_all
(
job_id
)
...
...
@@ -54,19 +54,19 @@ module Gitlab
end
def
size
job_trace_chunk
.
data
&
.
length
||
0
job_trace_chunk
.
data
&
.
bytesize
||
0
end
def
write!
(
data
)
raise
NotImplementedError
,
'Partial writing is not supported'
unless
params
[
:buffer_size
]
==
data
&
.
length
raise
NotImplementedError
,
'Partial writing is not supported'
unless
params
[
:buffer_size
]
==
data
&
.
bytesize
raise
NotImplementedError
,
'UPDATE (Overwriting data) is not supported'
if
job_trace_chunk
.
data
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
job_trace_chunk
.
data
=
data
job_trace_chunk
.
save!
data
.
length
data
.
bytesize
end
def
append!
(
data
)
...
...
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
View file @
91fe68a6
...
...
@@ -83,7 +83,7 @@ module Gitlab
def
write!
(
data
)
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
unless
redis
.
set
(
buffer_key
,
data
)
==
'OK'
raise
WriteError
,
'Failed to write'
...
...
@@ -96,7 +96,7 @@ module Gitlab
def
append!
(
data
)
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
raise
BufferKeyNotFoundError
,
'Buffer key is not found'
unless
redis
.
exists
(
buffer_key
)
...
...
@@ -104,7 +104,7 @@ module Gitlab
new_size
=
redis
.
append
(
buffer_key
,
data
)
appended_size
=
new_size
-
original_size
raise
WriteError
,
'Failed to append'
unless
appended_size
==
data
.
length
raise
WriteError
,
'Failed to append'
unless
appended_size
==
data
.
bytesize
appended_size
end
...
...
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
View file @
91fe68a6
...
...
@@ -84,7 +84,7 @@ module Gitlab
def
read
(
length
=
nil
,
outbuf
=
nil
)
out
=
""
until
eof?
||
(
length
&&
out
.
length
>=
length
)
until
eof?
||
(
length
&&
out
.
bytesize
>=
length
)
data
=
get_chunk
break
if
data
.
empty?
...
...
@@ -92,7 +92,7 @@ module Gitlab
@tell
+=
data
.
bytesize
end
out
=
out
[
0
,
length
]
if
length
&&
out
.
length
>
length
out
=
out
.
byteslice
(
0
,
length
)
if
length
&&
out
.
bytesize
>
length
out
end
...
...
@@ -104,15 +104,15 @@ module Gitlab
data
=
get_chunk
break
if
data
.
empty?
new_line
=
data
.
index
(
"
\n
"
)
new_line
_pos
=
byte_position
(
data
,
"
\n
"
)
if
!
new_line
.
nil?
out
<<
data
[
0
..
new_line
]
@tell
+=
new_line
+
1
break
else
if
new_line_pos
.
nil?
out
<<
data
@tell
+=
data
.
bytesize
else
out
<<
data
.
byteslice
(
0
..
new_line_pos
)
@tell
+=
new_line_pos
+
1
break
end
end
...
...
@@ -123,7 +123,7 @@ module Gitlab
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
if
mode
.
include?
(
'w'
)
write_as_overwrite
(
data
)
raise
NotImplementedError
,
"Overwrite is not supported"
elsif
mode
.
include?
(
'a'
)
write_as_append
(
data
)
end
...
...
@@ -157,27 +157,26 @@ module Gitlab
unless
in_range?
chunk_store
.
open
(
job_id
,
chunk_index
,
params_for_store
)
do
|
store
|
@chunk
=
store
.
get
@chunk_range
=
(
chunk_start
...
(
chunk_start
+
chunk
.
length
))
raise
ReadError
,
'Could not get a chunk'
unless
chunk
&&
chunk
.
present?
@chunk_range
=
(
chunk_start
...
(
chunk_start
+
chunk
.
bytesize
))
end
end
@chunk
[
chunk_offset
..
buffer_size
]
end
def
write_as_overwrite
(
data
)
raise
NotImplementedError
,
"Overwrite is not supported"
@chunk
.
byteslice
(
chunk_offset
,
buffer_size
)
end
def
write_as_append
(
data
)
@tell
=
size
data_size
=
data
.
size
data_size
=
data
.
byte
size
new_tell
=
tell
+
data_size
data_offset
=
0
until
tell
==
new_tell
writable_size
=
buffer_size
-
chunk_offset
writable_data
=
data
[
data_offset
...
(
data_offset
+
writable_size
)]
writable_data
=
data
.
byteslice
(
data_offset
,
writable_size
)
written_size
=
write_chunk
(
writable_data
)
data_offset
+=
written_size
...
...
@@ -199,7 +198,7 @@ module Gitlab
store
.
write!
(
data
)
end
raise
WriteError
,
'Written size mismatch'
unless
data
.
length
==
written_size
raise
WriteError
,
'Written size mismatch'
unless
data
.
bytesize
==
written_size
end
end
...
...
@@ -249,6 +248,25 @@ module Gitlab
def
calculate_size
(
job_id
)
chunk_store
.
chunks_size
(
job_id
)
end
def
byte_position
(
data
,
pattern_byte
)
index_as_string
=
data
.
index
(
pattern_byte
)
return
nil
unless
index_as_string
if
data
.
getbyte
(
index_as_string
)
==
pattern_byte
.
getbyte
(
0
)
index_as_string
else
data2
=
data
.
byteslice
(
index_as_string
,
100
)
additional_pos
=
0
data2
.
each_byte
do
|
b
|
break
if
b
==
pattern_byte
.
getbyte
(
0
)
additional_pos
+=
1
end
index_as_string
+
additional_pos
end
end
end
end
end
...
...
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
View file @
91fe68a6
...
...
@@ -8,6 +8,7 @@ module Gitlab
included
do
WriteError
=
Class
.
new
(
StandardError
)
ReadError
=
Class
.
new
(
StandardError
)
end
end
end
...
...
spec/fixtures/trace/sample_trace
View file @
91fe68a6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
View file @
91fe68a6
...
...
@@ -51,7 +51,7 @@ describe Gitlab::Ci::Trace::ChunkedFile::LiveTrace, :clean_gitlab_redis_cache do
end
context
'when offset is size'
do
let
(
:offset
)
{
sample_trace_raw
.
length
}
let
(
:offset
)
{
sample_trace_raw
.
bytesize
}
it
'does nothing'
do
expect
{
subject
}.
not_to
change
{
described_class
.
exist?
(
job_id
)
}
...
...
spec/support/shared_examples/lib/gitlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
View file @
91fe68a6
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment