php - Google Cloud Storage One file multiple access at the same time -


i'm using googlecloudstorage in gae-projekt , know happens when access 2 instances 1 file @ same time. created php-script, opens file, read it's content, add content , save this:

$usercontent = json_decode(file_get_contents("*** link ***")); $usercontent->abc = "test"; // changes file_put_contents("*** link ***", json_encode($usercontent); 

my worry while open file, instance opens , data gets lost. happen in case?

  • is file locked , other instance waiting?
  • is file locked , other instance aborts?
  • is data getting lost?

google cloud storage, per se, imposes no locking. both reads , writes gcs objects atomic -- each read contents of object entirely 1 version; each write totally replace object. no "intermediate stage" (with part of object being 1 version , rest version) can ever possibly exist.

but of course is quite possible "lose data" if multiple tasks attempting "modify" gcs object independently , w/o somehow syncing or negotiating among themselves! that's because gcs has no concept of "modifying" object: of reading object, , replacing object entirely.

so, task trying "modify" gcs object reads it, modifies whatever has in memory, overwrites object memory's contents. if multiple tasks independently "overwriting" same object, last overwrite "win", , obliterate previous ones.

i have no idea "gap-projekt" is, assuming we're talking gae (as per tags), it's reasonably easy multiple instances of gae app sync among themselves, using shared resources such memcache or gae datastore. such resources used denote instance "currently owns" gcs object, convention; other instance wait turn...


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -