You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/01/29 04:20:07 UTC

[GitHub] stashslash opened a new issue #401: concurrency transaction

stashslash opened a new issue #401: concurrency transaction
URL: https://github.com/apache/servicecomb-pack/issues/401
 
 
   there is a concurrency question with `servicecomb-pack`.
   
   eg:
   there are two global transaction hit on same record, when the first one failure with same reason and need compensate, and the second one success at the same time. the first compensate action maybe overwrite the second one.
   
   like the image, the timeline looks like:
   <img width="648" alt="timeline" src="https://user-images.githubusercontent.com/45448340/51882535-2e593c00-23ba-11e9-9cd2-0a002b5c3126.png">
   i test the `servicecomb-pack` and it seems not handled such case. 
   
   actually, im not sure its `servicecomb-pack` problem or saga, saga seems not describe that something like global lock of transaction.
   
   and there is snippet of my test code of `CarBookingService`.
   ```
     private List<Integer> ids = new CopyOnWriteArrayList<>();
     private Map<Integer, CarBooking> bookings = new ConcurrentHashMap<>();
   
     @Compensable(compensationMethod = "cancel")
     void order(CarBooking booking) {
       booking.confirm();
   
       ids.add(booking.getId());
       bookings.put(booking.getId(), booking);
     }
   
     /**
      * simulate update the last booking confirm status
      */
     @Compensable(compensationMethod = "cancel")
     void reConfirm() {
       CarBooking carBooking = bookings.get(ids.get(ids.size() - 1));
       if (carBooking != null) {
         carBooking.confirm();
       }
     }
   
     void cancel(CarBooking booking) {
       Integer id = booking.getId();
       if (bookings.containsKey(id)) {
   
         // make some latency of compensation
         try {
           Thread.sleep(1000);
         } catch (InterruptedException e) {
         }
   
         bookings.get(id).cancel();
       }
     }
   ```
   if call `order` and `reconfirm` at the same time, it maybe get the result:
   `{"id":1,"name":"test","amount":1,"confirmed":false,"cancelled":true}`
   but expected:
   `{"id":5,"name":"test","amount":1,"confirmed":true,"cancelled":false}`
   
   it maybe not a good test case in real scene, i just want test the  concurrency.
   
   so should `servicecomb-pack` need a global lock of transaction? or do something prevent the compensation happens.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services