1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

MassParse: Fix multi-threaded issues b/c wbase caches aren't locked

This commit is contained in:
gnosygnu 2019-04-26 22:26:54 -04:00
parent 74b63d5f08
commit 42953aaa0f
2 changed files with 18 additions and 14 deletions

View File

@ -38,13 +38,15 @@ public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
byte[] pid_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name);
// get from cache
int rv = cache.Get_as_int_or(pid_key, -1);
if (rv == -1) {
// get from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_pid(lang_key, pid_name);
if (rv == Wbase_pid.Id_null) rv = Wbase_pid.Id_null;
Add(pid_key, rv);
synchronized (cache) {
int rv = cache.Get_as_int_or(pid_key, -1);
if (rv == -1) {
// get from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_pid(lang_key, pid_name);
if (rv == Wbase_pid.Id_null) rv = Wbase_pid.Id_null;
Add(pid_key, rv);
}
return rv;
}
return rv;
}
}

View File

@ -39,14 +39,16 @@ public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
byte[] key = Bry_.Add(wdata_wiki_abrv, Byte_ascii.Pipe_bry, ttl.Ns().Num_bry(), Byte_ascii.Pipe_bry, ttl.Page_db());
// get from cache
byte[] rv = (byte[])cache.Get_by(key);
if (rv == null) {
// get from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wdata_wiki_abrv, ttl.Ns().Id(), ttl.Page_db());
byte[] val_for_hash = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
this.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
synchronized (cache) {
byte[] rv = (byte[])cache.Get_by(key);
if (rv == null) {
// get from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wdata_wiki_abrv, ttl.Ns().Id(), ttl.Page_db());
byte[] val_for_hash = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
this.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
}
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null which is what callers expect
}
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null which is what callers expect
}
private void Add(byte[] key, byte[] val) {
synchronized (cache) { // LOCK:app-level