Review Board 1.7.22


HBASE-4720 Implement atomic update operations (checkAndPut, checkAndDelete) for REST client/server

Review Request #5259 - Created May 29, 2012 and submitted

Jimmy Xiang
trunk
HBASE-4720
Reviewers
hbase
apurtell, jdcryans, stack, tedyu
hbase-git
Basically, it is Mubarak's patch.  I enhanced a little bit.  The jira is dormant for a while.  I'd like to get it going.
Will backport to 94, 92 and 90 after it's integrated into trunk.
mvn -PrunMediumTests -Dtest=Test*Resource clean test

Changes between revision 1 and 3

1 2 3
1 2 3

  1. hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java: Loading...
hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java
Diff Revision 1 Diff Revision 3
[20] 52 lines
[+20]
53

    
   
53

   
54
@InterfaceAudience.Private
54
@InterfaceAudience.Private
55
public class RowResource extends ResourceBase {
55
public class RowResource extends ResourceBase {
56
  private static final Log LOG = LogFactory.getLog(RowResource.class);
56
  private static final Log LOG = LogFactory.getLog(RowResource.class);
57

    
   
57

   

    
   
58
  static final String CHECK_PUT = "put";

    
   
59
  static final String CHECK_DELETE = "delete";

    
   
60

   
58
  TableResource tableResource;
61
  TableResource tableResource;
59
  RowSpec rowspec;
62
  RowSpec rowspec;
60
  private String check = null;
63
  private String check = null;
61

    
   
64

   
62
  /**
65
  /**
[+20] [20] 88 lines
[+20] [+] public Response getBinary(final @Context UriInfo uriInfo) {
151
  Response update(final CellSetModel model, final boolean replace) {
154
  Response update(final CellSetModel model, final boolean replace) {
152
    servlet.getMetrics().incrementRequests(1);
155
    servlet.getMetrics().incrementRequests(1);
153
    if (servlet.isReadOnly()) {
156
    if (servlet.isReadOnly()) {
154
      throw new WebApplicationException(Response.Status.FORBIDDEN);
157
      throw new WebApplicationException(Response.Status.FORBIDDEN);
155
    }
158
    }

    
   
159

   

    
   
160
    if (CHECK_PUT.equalsIgnoreCase(check)) {

    
   
161
      return checkAndPut(model);

    
   
162
    } else if (CHECK_DELETE.equalsIgnoreCase(check)) {

    
   
163
      return checkAndDelete(model);

    
   
164
    } else if (check != null && check.length() > 0) {

    
   
165
      LOG.warn("Unknown check value: " + check + ", ignored");

    
   
166
    }

    
   
167

   
156
    HTablePool pool = servlet.getTablePool();
168
    HTablePool pool = servlet.getTablePool();
157
    HTableInterface table = null;
169
    HTableInterface table = null;
158
    try {
170
    try {
159
      List<RowModel> rows = model.getRows();
171
      List<RowModel> rows = model.getRows();
160
      List<Put> puts = new ArrayList<Put>();
172
      List<Put> puts = new ArrayList<Put>();
[+20] [20] 116 lines
[+20] public Response getBinary(final @Context UriInfo uriInfo) {
277
  @PUT
289
  @PUT
278
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
290
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
279
  public Response put(final CellSetModel model,
291
  public Response put(final CellSetModel model,
280
      final @Context UriInfo uriInfo) {
292
      final @Context UriInfo uriInfo) {
281
    if (LOG.isDebugEnabled()) {
293
    if (LOG.isDebugEnabled()) {
282
      LOG.debug("PUT " + uriInfo.getAbsolutePath());
294
      LOG.debug("POST " + uriInfo.getAbsolutePath()
283
    }
295
        + " " + uriInfo.getQueryParameters());
284
    if ("put".equals(check)) {

   
285
      return checkAndPut(model);

   
286
    } else if ("delete".equals(check)) {

   
287
      return checkAndDelete(model);

   
288
    } else {

   
289
      if (check != null && check.length() > 0) {

   
290
        LOG.warn("Unknown check value: " + check + ", ignored");

   
291
      }
296
    }
292
      return update(model, true);
297
    return update(model, true);
293
    }
298
  }
294
  }

   
295

    
   
299

   
296
  @PUT
300
  @PUT
297
  @Consumes(MIMETYPE_BINARY)
301
  @Consumes(MIMETYPE_BINARY)
298
  public Response putBinary(final byte[] message,
302
  public Response putBinary(final byte[] message,
299
      final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
303
      final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
[+20] [20] 6 lines
[+20] public Response putBinary(final byte[] message,
306
  @POST
310
  @POST
307
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
311
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
308
  public Response post(final CellSetModel model,
312
  public Response post(final CellSetModel model,
309
      final @Context UriInfo uriInfo) {
313
      final @Context UriInfo uriInfo) {
310
    if (LOG.isDebugEnabled()) {
314
    if (LOG.isDebugEnabled()) {
311
      LOG.debug("POST " + uriInfo.getAbsolutePath());
315
      LOG.debug("POST " + uriInfo.getAbsolutePath()
312
    }
316
        + " " + uriInfo.getQueryParameters());
313
    if ("put".equals(check)) {

   
314
      return checkAndPut(model);

   
315
    } else if ("delete".equals(check)) {

   
316
      return checkAndDelete(model);

   
317
    } else {

   
318
      if (check != null && check.length() > 0) {

   
319
        LOG.warn("Unknown check value: " + check + ", ignored");

   
320
      }
317
    }
321
      return update(model, false);
318
    return update(model, false);
322
    }
319
  }
323
  }

   
324

    
   
320

   
325
  @POST
321
  @POST
326
  @Consumes(MIMETYPE_BINARY)
322
  @Consumes(MIMETYPE_BINARY)
327
  public Response postBinary(final byte[] message,
323
  public Response postBinary(final byte[] message,
328
      final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
324
      final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
[+20] [20] 66 lines
[+20] [+] public Response delete(final @Context UriInfo uriInfo) {
395
   *
391
   *
396
   * @param model instance of CellSetModel
392
   * @param model instance of CellSetModel
397
   * @return Response 200 OK, 304 Not modified, 400 Bad request
393
   * @return Response 200 OK, 304 Not modified, 400 Bad request
398
   */
394
   */
399
  Response checkAndPut(final CellSetModel model) {
395
  Response checkAndPut(final CellSetModel model) {
400
    servlet.getMetrics().incrementRequests(1);

   
401
    if (servlet.isReadOnly()) {

   
402
      throw new WebApplicationException(Response.Status.FORBIDDEN);

   
403
    }

   
404
    HTablePool pool = servlet.getTablePool();
396
    HTablePool pool = servlet.getTablePool();
405
    HTableInterface table = null;
397
    HTableInterface table = null;
406
    try {
398
    try {
407
      if (model.getRows().size() != 1) {
399
      if (model.getRows().size() != 1) {
408
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
400
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
[+20] [20] 66 lines
[+20] public Response delete(final @Context UriInfo uriInfo) {
475
   *
467
   *
476
   * @param model instance of CellSetModel
468
   * @param model instance of CellSetModel
477
   * @return Response 200 OK, 304 Not modified, 400 Bad request
469
   * @return Response 200 OK, 304 Not modified, 400 Bad request
478
   */
470
   */
479
  Response checkAndDelete(final CellSetModel model) {
471
  Response checkAndDelete(final CellSetModel model) {
480
    servlet.getMetrics().incrementRequests(1);

   
481
    if (servlet.isReadOnly()) {

   
482
      throw new WebApplicationException(Response.Status.FORBIDDEN);

   
483
    }

   
484
    HTablePool pool = servlet.getTablePool();
472
    HTablePool pool = servlet.getTablePool();
485
    HTableInterface table = null;
473
    HTableInterface table = null;
486
    Delete delete = null;
474
    Delete delete = null;
487
    try {
475
    try {
488
      if (model.getRows().size() != 1) {
476
      if (model.getRows().size() != 1) {
[+20] [20] 53 lines
  1. hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java: Loading...