Commit dfcd47ea authored by Krit Punpreuk's avatar Krit Punpreuk

add handle error

parent 8842e6ac
...@@ -144,6 +144,8 @@ router.get('/:id/bsstime', async (req, res, next) => { ...@@ -144,6 +144,8 @@ router.get('/:id/bsstime', async (req, res, next) => {
if (query.debug == 'true') { if (query.debug == 'true') {
debug = true debug = true
}else {
debug = false
} }
// Pick only one // Pick only one
...@@ -207,6 +209,9 @@ router.get('/:id/bsstime', async (req, res, next) => { ...@@ -207,6 +209,9 @@ router.get('/:id/bsstime', async (req, res, next) => {
} else { } else {
let range = await searchSeq(bss_full_path, t, l, u, "seek") let range = await searchSeq(bss_full_path, t, l, u, "seek")
from_seq = range[0] from_seq = range[0]
if(!from_seq) {
return respHelper.response400('Error read on storage');
}
limit = (range[range.length - 1] - range[0]) + 1 limit = (range[range.length - 1] - range[0]) + 1
} }
printLog("found: " + from_seq + " limit: " + limit,true) printLog("found: " + from_seq + " limit: " + limit,true)
...@@ -245,7 +250,9 @@ router.get('/:id/bsstime', async (req, res, next) => { ...@@ -245,7 +250,9 @@ router.get('/:id/bsstime', async (req, res, next) => {
from_seq = found[0] from_seq = found[0]
found = await searchSeq(bss_full_path, t[1], from_seq, u2, "right") found = await searchSeq(bss_full_path, t[1], from_seq, u2, "right")
limit = found[0] - from_seq + 1 limit = found[0] - from_seq + 1
if(!from_seq) {
return respHelper.response400('Error read on storage');
}
// prevent no limit output // prevent no limit output
if (limit == 0 || limit < 0) { if (limit == 0 || limit < 0) {
limit = 1; limit = 1;
...@@ -417,6 +424,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) { ...@@ -417,6 +424,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
let result = [] let result = []
let rd = bss.reader(); let rd = bss.reader();
let rec_count = rd.count(); let rec_count = rd.count();
printLog("total record:"+rec_count,debug);
let last_seq = rec_count - 1 let last_seq = rec_count - 1
let OATZ = Number(rd.rootData.OATZ) let OATZ = Number(rd.rootData.OATZ)
...@@ -439,7 +447,6 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) { ...@@ -439,7 +447,6 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
// Prevent out of bound // Prevent out of bound
if (u >= rec_count) { u = last_seq } if (u >= rec_count) { u = last_seq }
if (l < 1) { l = 1 } if (l < 1) { l = 1 }
let idx = l let idx = l
let cont = true; let cont = true;
let resultIdx = 0 let resultIdx = 0
...@@ -457,6 +464,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) { ...@@ -457,6 +464,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
printLog("l m u : " + l + ", " + idx + ", " + u,debug); printLog("l m u : " + l + ", " + idx + ", " + u,debug);
let id = (new ObjId(obj.header.ID)).toString(); let id = (new ObjId(obj.header.ID)).toString();
printLog("id:"+id,debug);
let dataout = {}; let dataout = {};
// dataout.ts = parseInt(id.substring(16, id.length), 16) // dataout.ts = parseInt(id.substring(16, id.length), 16)
dataout.ts = obj.meta._ts dataout.ts = obj.meta._ts
...@@ -490,13 +498,18 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) { ...@@ -490,13 +498,18 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
result.push(dataout.seq) result.push(dataout.seq)
cont = false; cont = false;
} }
printLog("before update l or u",debug);
printLog(l,debug);
printLog(u,debug);
printLog(dataout,debug);
if (dataout.ts < t) { if (dataout.ts < t) {
l = Number(dataout.seq) l = Number(dataout.seq)
} else { } else {
u = Number(dataout.seq) - 1 u = Number(dataout.seq) - 1
} }
idx = Math.ceil((Number(l) + Number(u)) / 2) idx = Math.ceil((Number(l) + Number(u)) / 2)
printLog("move to : " + idx,debug);
rd.moveTo(idx); rd.moveTo(idx);
} }
resultIdx++ resultIdx++
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment