google app engine - Advice needed for Concurrent read and write scenario in GAE Python NDB -


i developing ticket booking website using gae python. website lists available vehicles on selected date , allows customer book it.
when customer selects vehicle , proceeds booking, want temporarily block vehicle day nobody else books using our website. temporary block should revoked automatically in next 2 minutes if customer fails make payment correctly.
planning have model below:

class availability(ndb.model):      vehicle = ndb.stringproperty()      date = ndb.datetimeproperty()      status = ndb.stringproperty() #"available" or "booked"      temporary_blocking_time = ndb.datetimeproperty()  

i update "temporary_blocking_time" variable selected vehicle , date. when other customer searches vehicle on same date, "temporary_blocking_time" vehicle checked , if less 2 minutes old, vehicle not listed customer book.

t0 < t1 < t2 < t3
problem logic: when customer "x" wants proceed book given vehicle, read "temporary_blocking_time" of vehicle(at time "t1") , write current time that(at time "t2").
problem can arise when customer has selected same vehicle same date, , has read the "temporary_blocking_time" @ time "t0" , write @ "t3". overwrite customer "x"s booking.

to add problem, consistency issues might come.

how can improve logic design solve problem

consider doing get see if temporary_blocking_time active , put set inside transaction. make put @ t3 fail since put @ t2 happened after t0.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -