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 2 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 2 Diff Revision 3
[20] 149 lines
[+20] [+] public Response getBinary(final @Context UriInfo uriInfo) {
150
                  Response.Status.SERVICE_UNAVAILABLE);
150
                  Response.Status.SERVICE_UNAVAILABLE);
151
    }
151
    }
152
  }
152
  }
153

    
   
153

   
154
  Response update(final CellSetModel model, final boolean replace) {
154
  Response update(final CellSetModel model, final boolean replace) {
Moved from 163

    
   
155
    servlet.getMetrics().incrementRequests(1);
Moved from 164

    
   
156
    if (servlet.isReadOnly()) {
Moved from 165

    
   
157
      throw new WebApplicationException(Response.Status.FORBIDDEN);
Moved from 166

    
   
158
    }

    
   
159

   
155
    if (CHECK_PUT.equalsIgnoreCase(check)) {
160
    if (CHECK_PUT.equalsIgnoreCase(check)) {
156
      return checkAndPut(model);
161
      return checkAndPut(model);
157
    } else if (CHECK_DELETE.equalsIgnoreCase(check)) {
162
    } else if (CHECK_DELETE.equalsIgnoreCase(check)) {
158
      return checkAndDelete(model);
163
      return checkAndDelete(model);
159
    } else if (check != null && check.length() > 0) {
164
    } else if (check != null && check.length() > 0) {
160
      LOG.warn("Unknown check value: " + check + ", ignored");
165
      LOG.warn("Unknown check value: " + check + ", ignored");
161
    }
166
    }
162

    
   
167

   
163
    servlet.getMetrics().incrementRequests(1);

   
164
    if (servlet.isReadOnly()) {

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

   
166
    }

   
167
    HTablePool pool = servlet.getTablePool();
168
    HTablePool pool = servlet.getTablePool();
168
    HTableInterface table = null;
169
    HTableInterface table = null;
169
    try {
170
    try {
170
      List<RowModel> rows = model.getRows();
171
      List<RowModel> rows = model.getRows();
171
      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) {
288
  @PUT
289
  @PUT
289
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
290
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
290
  public Response put(final CellSetModel model,
291
  public Response put(final CellSetModel model,
291
      final @Context UriInfo uriInfo) {
292
      final @Context UriInfo uriInfo) {
292
    if (LOG.isDebugEnabled()) {
293
    if (LOG.isDebugEnabled()) {
293
      LOG.debug("PUT " + uriInfo.getAbsolutePath());
294
      LOG.debug("POST " + uriInfo.getAbsolutePath()

    
   
295
        + " " + uriInfo.getQueryParameters());
294
    }
296
    }
295
    return update(model, true);
297
    return update(model, true);
296
  }
298
  }
297

    
   
299

   
298
  @PUT
300
  @PUT
[+20] [20] 9 lines
[+20] [+] public Response putBinary(final byte[] message,
308
  @POST
310
  @POST
309
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
311
  @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
310
  public Response post(final CellSetModel model,
312
  public Response post(final CellSetModel model,
311
      final @Context UriInfo uriInfo) {
313
      final @Context UriInfo uriInfo) {
312
    if (LOG.isDebugEnabled()) {
314
    if (LOG.isDebugEnabled()) {
313
      LOG.debug("POST " + uriInfo.getAbsolutePath());
315
      LOG.debug("POST " + uriInfo.getAbsolutePath()

    
   
316
        + " " + uriInfo.getQueryParameters());
314
    }
317
    }
315
    return update(model, false);
318
    return update(model, false);
316
  }
319
  }
317

    
   
320

   
318
  @POST
321
  @POST
[+20] [20] 69 lines
[+20] [+] public Response delete(final @Context UriInfo uriInfo) {
388
   *
391
   *
389
   * @param model instance of CellSetModel
392
   * @param model instance of CellSetModel
390
   * @return Response 200 OK, 304 Not modified, 400 Bad request
393
   * @return Response 200 OK, 304 Not modified, 400 Bad request
391
   */
394
   */
392
  Response checkAndPut(final CellSetModel model) {
395
  Response checkAndPut(final CellSetModel model) {
393
    servlet.getMetrics().incrementRequests(1);

   
394
    if (servlet.isReadOnly()) {

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

   
396
    }

   
397
    HTablePool pool = servlet.getTablePool();
396
    HTablePool pool = servlet.getTablePool();
398
    HTableInterface table = null;
397
    HTableInterface table = null;
399
    try {
398
    try {
400
      if (model.getRows().size() != 1) {
399
      if (model.getRows().size() != 1) {
401
        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) {
468
   *
467
   *
469
   * @param model instance of CellSetModel
468
   * @param model instance of CellSetModel
470
   * @return Response 200 OK, 304 Not modified, 400 Bad request
469
   * @return Response 200 OK, 304 Not modified, 400 Bad request
471
   */
470
   */
472
  Response checkAndDelete(final CellSetModel model) {
471
  Response checkAndDelete(final CellSetModel model) {
473
    servlet.getMetrics().incrementRequests(1);

   
474
    if (servlet.isReadOnly()) {

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

   
476
    }

   
477
    HTablePool pool = servlet.getTablePool();
472
    HTablePool pool = servlet.getTablePool();
478
    HTableInterface table = null;
473
    HTableInterface table = null;
479
    Delete delete = null;
474
    Delete delete = null;
480
    try {
475
    try {
481
      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...