diff options
| author | ruki <[email protected]> | 2022-06-19 22:48:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-06-19 22:48:46 +0800 |
| commit | 01eeb3325c51d18f79b61303fb4d17af011b7dd0 (patch) | |
| tree | 5cfd2d47d5d5ae62a3b7ffa0a9898b1684fd4864 | |
| parent | eb965315b1030cc2de426909500d34f99d281943 (diff) | |
cache outdata/errdata for remote cache
4 files changed, 26 insertions, 11 deletions
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index 13bebcbdf..882f50f9a 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -150,12 +150,16 @@ function get(cachekey) if os.isfile(objectfile_cached) then _g.hit_count = (_g.hit_count or 0) + 1 return objectfile_cached, objectfile_infofile - elseif remote_cache_client.is_connected() and - remote_cache_client.singleton():pull(cachekey, objectfile_cached) and - os.isfile(objectfile_cached) then - _g.hit_count = (_g.hit_count or 0) + 1 - _g.remote_hit_count = (_g.remote_hit_count or 0) + 1 - return objectfile_cached, objectfile_infofile + elseif remote_cache_client.is_connected() then + local exists, extrainfo = remote_cache_client.singleton():pull(cachekey, objectfile_cached) + if exists and os.isfile(objectfile_cached) then + _g.hit_count = (_g.hit_count or 0) + 1 + _g.remote_hit_count = (_g.remote_hit_count or 0) + 1 + if extrainfo then + io.save(objectfile_infofile, extrainfo) + end + return objectfile_cached, objectfile_infofile + end end end @@ -179,7 +183,7 @@ function put(cachekey, objectfile, extrainfo) local cacheinfo = remote_cache_client.singleton():cacheinfo(cachekey) if not cacheinfo or not cacheinfo.exists then _g.remote_newfiles_count = (_g.remote_newfiles_count or 0) + 1 - remote_cache_client.singleton():push(cachekey, objectfile) + remote_cache_client.singleton():push(cachekey, objectfile, extrainfo) end end end diff --git a/xmake/modules/private/service/message.lua b/xmake/modules/private/service/message.lua index b28de5af6..7338b06ac 100644 --- a/xmake/modules/private/service/message.lua +++ b/xmake/modules/private/service/message.lua @@ -273,7 +273,8 @@ function new_push(session_id, filename, opt) code = message.CODE_PUSH, filename = filename, session_id = session_id, - token = opt.token + token = opt.token, + extrainfo = opt.extrainfo }) end diff --git a/xmake/modules/private/service/remote_cache/client.lua b/xmake/modules/private/service/remote_cache/client.lua index 969d3c654..87f0f46ed 100644 --- a/xmake/modules/private/service/remote_cache/client.lua +++ b/xmake/modules/private/service/remote_cache/client.lua @@ -179,6 +179,7 @@ function remote_cache_client:pull(cachekey, cachefile) local errors local ok = false local exists = false + local extrainfo dprint("%s: pull cache(%s) in %s:%d ..", self, cachekey, addr, port) local stream = socket_stream(sock) if stream:send_msg(message.new_pull(session_id, cachekey, {token = self:token()})) and stream:flush() then @@ -189,6 +190,7 @@ function remote_cache_client:pull(cachekey, cachefile) if msg:success() then ok = true exists = msg:body().exists + extrainfo = msg:body().extrainfo else errors = msg:errors() end @@ -203,11 +205,11 @@ function remote_cache_client:pull(cachekey, cachefile) else dprint("%s: pull cache(%s) failed in %s:%d, %s", self, cachekey, addr, port, errors or "unknown") end - return exists + return exists, extrainfo end -- push cache file -function remote_cache_client:push(cachekey, cachefile) +function remote_cache_client:push(cachekey, cachefile, extrainfo) assert(self:is_connected(), "%s: has been not connected!", self) local addr = self:addr() local port = self:port() @@ -217,7 +219,7 @@ function remote_cache_client:push(cachekey, cachefile) local ok = false dprint("%s: push cache(%s) in %s:%d ..", self, cachekey, addr, port) local stream = socket_stream(sock) - if stream:send_msg(message.new_push(session_id, cachekey, {token = self:token()})) and stream:flush() then + if stream:send_msg(message.new_push(session_id, cachekey, {token = self:token(), extrainfo = extrainfo})) and stream:flush() then if stream:send_file(cachefile, {compress = os.filesize(cachefile) > 4096}) then local msg = stream:recv_msg() if msg then diff --git a/xmake/modules/private/service/remote_cache/server_session.lua b/xmake/modules/private/service/remote_cache/server_session.lua index 38d86e55e..6ab5d9a06 100644 --- a/xmake/modules/private/service/remote_cache/server_session.lua +++ b/xmake/modules/private/service/remote_cache/server_session.lua @@ -81,11 +81,15 @@ function server_session:pull(respmsg) local stream = self:stream() local cachekey = body.filename local cachefile = path.join(self:cachedir(), cachekey:sub(1, 2), cachekey) + local cacheinfofile = cachefile .. ".txt" vprint("pull cachefile(%s) ..", cachekey) -- send cache file if os.isfile(cachefile) then body.exists = true + if os.isfile(cacheinfofile) then + body.extrainfo = io.load(cacheinfofile) + end if not stream:send_file(cachefile, {compress = os.filesize(cachefile) > 4096}) then raise("send %s failed!", cachefile) end @@ -103,10 +107,14 @@ function server_session:push(respmsg) local stream = self:stream() local cachekey = body.filename local cachefile = path.join(self:cachedir(), cachekey:sub(1, 2), cachekey) + local cacheinfofile = cachefile .. ".txt" vprint("push cachefile(%s) ..", cachekey) if not stream:recv_file(cachefile) then raise("recv %s failed!", cachefile) end + if body.extrainfo then + io.save(cacheinfofile, body.extrainfo) + end end -- get file info |
