Invalidate warmed wasm modules precisely
This commit is contained in:
+11
-4
@@ -75,7 +75,9 @@ struct WasmUnitModule
|
||||
{
|
||||
String source_path; // absolute .uce path
|
||||
String wasm_path; // artifact in the unit cache
|
||||
time_t mtime = 0;
|
||||
u64 modified_ns = 0;
|
||||
u64 changed_ns = 0;
|
||||
u64 size = 0;
|
||||
WasmDylinkInfo dylink;
|
||||
WasmAbiInfo abi;
|
||||
std::optional<wasmtime::Module> module;
|
||||
@@ -640,13 +642,17 @@ public:
|
||||
return(nullptr);
|
||||
}
|
||||
auto cached = module_cache.find(wasm_path);
|
||||
if(cached != module_cache.end() && cached->second->mtime == st.st_mtime)
|
||||
u64 modified_ns = (u64)st.st_mtim.tv_sec * 1000000000ull + (u64)st.st_mtim.tv_nsec;
|
||||
u64 changed_ns = (u64)st.st_ctim.tv_sec * 1000000000ull + (u64)st.st_ctim.tv_nsec;
|
||||
if(cached != module_cache.end() && cached->second->modified_ns == modified_ns && cached->second->changed_ns == changed_ns && cached->second->size == (u64)st.st_size)
|
||||
return(cached->second);
|
||||
|
||||
auto unit = std::make_shared<WasmUnitModule>();
|
||||
unit->source_path = source_path;
|
||||
unit->wasm_path = wasm_path;
|
||||
unit->mtime = st.st_mtime;
|
||||
unit->modified_ns = modified_ns;
|
||||
unit->changed_ns = changed_ns;
|
||||
unit->size = (u64)st.st_size;
|
||||
std::vector<u8> bytes;
|
||||
if(!wasm_read_file(wasm_path, bytes))
|
||||
{
|
||||
@@ -696,7 +702,8 @@ private:
|
||||
struct stat cached_stat;
|
||||
if(stat(cached_path.c_str(), &cached_stat) == 0 && stat(wasm_path.c_str(), &wasm_stat) == 0)
|
||||
{
|
||||
if(cached_stat.st_mtime > wasm_stat.st_mtime)
|
||||
if(cached_stat.st_mtim.tv_sec > wasm_stat.st_mtim.tv_sec ||
|
||||
(cached_stat.st_mtim.tv_sec == wasm_stat.st_mtim.tv_sec && cached_stat.st_mtim.tv_nsec > wasm_stat.st_mtim.tv_nsec))
|
||||
{
|
||||
auto deserialized = wasmtime::Module::deserialize_file(engine, cached_path);
|
||||
if(deserialized)
|
||||
|
||||
Reference in New Issue
Block a user