Skip to content

Commit

Permalink
Update HBaseResourceStore.java
Browse files Browse the repository at this point in the history
Avoid resource inconsistent caused by hbase rpc timeout
  • Loading branch information
ulysses-you authored and shaofengshi committed Oct 12, 2018
1 parent 8581322 commit 562e88d
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
Expand Down Expand Up @@ -317,13 +318,20 @@ protected long checkAndPutResourceImpl(String resPath, byte[] content, long oldT
byte[] bOldTS = oldTS == 0 ? null : Bytes.toBytes(oldTS);
Put put = buildPut(resPath, newTS, row, content, table);

boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put);
logger.trace("Update row " + resPath + " from oldTs: " + oldTS + ", to newTs: " + newTS
+ ", operation result: " + ok);
if (!ok) {
try {
boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put);
logger.trace("Update row " + resPath + " from oldTs: " + oldTS + ", to newTs: " + newTS + ", operation result: " + ok);
if (!ok) {
long real = getResourceTimestampImpl(resPath);
throw new WriteConflictException(
"Overwriting conflict " + resPath + ", expect old TS " + oldTS + ", but it is " + real);
}
} catch (RetriesExhaustedException e){
long real = getResourceTimestampImpl(resPath);
throw new WriteConflictException(
"Overwriting conflict " + resPath + ", expect old TS " + oldTS + ", but it is " + real);
// rpc timeout but resource has been already updated
if(newTS != real){
throw e;
}
}

return newTS;
Expand Down

0 comments on commit 562e88d

Please sign in to comment.