<p>I have clustered applications that requires one of the nodes to be designated as the master. The cluster nodes are tracked in a table with <strong>nodeID</strong>, <strong>isMaster</strong>, <strong>lastTimestamp</strong> columns.</p>

<p>Each node in the cluster will try to become a master every <strong>X</strong> seconds. Node can only become a master if either</p>

<ul>
<li>there is no other master nodes </li>
<li>the <strong>lastTimestamp</strong> on current master node is older by <strong>2*X</strong></li>
</ul>

<p>When one of the above conditions is satisfied</p>

<ul>
<li>the current master node's <strong>isMaster</strong> should be cleared</li>
<li>the new master node's <strong>isMaster</strong> should be set</li>
<li>the new master node's <strong>lastTimestamp</strong> should be set to 'now' timestamp.</li>
</ul>

<p>What is the <strong>single</strong> (portable) SQL statement to achieve the above without the possibility of two or more nodes becoming the master?</p>

The normal way of avoiding the "delete then move fails problem" is:
Write to file.new
Move file.current to file.old
Move file.new to file.current
Delete file.new
Then when you come to read, use file.new if file.current is missing, deleting file.old if you see it.
Checking for whether or not the file is available: try opening it for write, but appending to the end. Of course, you'll need to close the handle before you then move it, and in-between someone else could open it - but it would at least be a
reasonable
optimisation.
Not sure about copying summaries etc, I'm afraid.