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,6 +38,7 @@ 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); byte[] pid_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name);
// get from cache // get from cache
synchronized (cache) {
int rv = cache.Get_as_int_or(pid_key, -1); int rv = cache.Get_as_int_or(pid_key, -1);
if (rv == -1) { if (rv == -1) {
// get from db // get from db
@ -48,3 +49,4 @@ public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
return rv; return rv;
} }
} }
}

View File

@ -39,6 +39,7 @@ 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()); 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 // get from cache
synchronized (cache) {
byte[] rv = (byte[])cache.Get_by(key); byte[] rv = (byte[])cache.Get_by(key);
if (rv == null) { if (rv == null) {
// get from db // get from db
@ -48,6 +49,7 @@ public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
} }
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) { private void Add(byte[] key, byte[] val) {
synchronized (cache) { // LOCK:app-level synchronized (cache) { // LOCK:app-level
if (!cache.Has(key)) if (!cache.Has(key))