Skip to content

Commit 5535554

Browse files
author
shuwen5
committed
add make_aws_put_s3_writer
1 parent 85b4447 commit 5535554

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

lib/pipe/writer.lua

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local httplib = require("pipe.httplib")
22
local strutil = require("acid.strutil")
3+
local tableutil = require("acid.tableutil")
34
local rpc_logging = require("acid.rpc_logging")
45
local acid_setutil = require("acid.setutil")
56
local s3_client = require('resty.aws_s3.client')
@@ -261,7 +262,7 @@ function _M.make_quorum_http_writers(dests, writer_opts, quorum)
261262
return nil, 'NotEnoughConnect', to_str('quorum:', quorum, ", actual:", n_ok)
262263
end
263264

264-
function _M.make_aws_put_s3_writer(access_key, secret_key, endpoint, params, opts)
265+
function _M.make_put_s3_writer(access_key, secret_key, endpoint, params, opts)
265266
local s3_cli, err_code, err_msg =
266267
s3_client.new(access_key, secret_key, endpoint, opts)
267268
if err_code ~= nil then
@@ -275,8 +276,11 @@ function _M.make_aws_put_s3_writer(access_key, secret_key, endpoint, params, opt
275276
end
276277

277278
return function(pobj, ident)
278-
local chunk_writer =
279-
aws_chunk_writer:new(request.signer, request.auth_ctx)
279+
local chunk_writer
280+
if opts.aws_chunk == true then
281+
chunk_writer =
282+
aws_chunk_writer:new(request.signer, request.auth_ctx)
283+
end
280284

281285
local _, err_code, err_msg = s3_cli:send_request(
282286
request.verb, request.uri, request.headers,request.body)
@@ -290,8 +294,12 @@ function _M.make_aws_put_s3_writer(access_key, secret_key, endpoint, params, opt
290294
return nil, err_code, err_msg
291295
end
292296

293-
local chunked_data = chunk_writer:make_chunk(data)
294-
local _, err_code, err_msg = s3_cli:send_body(chunked_data)
297+
local send_data = data
298+
if opts.aws_chunk == true then
299+
send_data = chunk_writer:make_chunk(send_data)
300+
end
301+
302+
local _, err_code, err_msg = s3_cli:send_body(send_data)
295303
if err_code ~= nil then
296304
return nil, err_code, err_msg
297305
end
@@ -305,4 +313,11 @@ function _M.make_aws_put_s3_writer(access_key, secret_key, endpoint, params, opt
305313
end
306314
end
307315

316+
function _M.make_aws_put_s3_writer(access_key, secret_key, endpoint, params, opts)
317+
opts = tableutil.dup(opts or {}, true)
318+
opts.aws_chunk = true
319+
320+
return _M.make_put_s3_writer(access_key, secret_key, endpoint, params, opts)
321+
end
322+
308323
return _M

0 commit comments

Comments
 (0)