Write Authorities
Dynamic control handoff with write authorities for concurrent access.
Writers support dynamic control handoff. Multiple writers can be opened on a channel at the same time, but only one writer is allowed to write to the channel. To determine which writer has control, an authority from 0 to 255 is assigned to each writer (or, optionally, each channel in the writer). The writer with the highest authority will be allowed to write. If two writers have the same authority, the writer that opened first will be allowed to write. For more information, see the concepts page.
By default, writers are opened with an authority of ABSOLUTE (255). This means that no
other writers can write to the channel as long as the writer is open.
Same Authority on All Channels
To open a writer with the same authority on all channels, pass the authorities
parameter with an integer.
writer = client.open_writer(
start=sy.TimeStamp.now(),
channels=["time", "temperature"],
authorities=100,
) const writer = await client.openWriter({
start: TimeStamp.now(),
channels: ["time", "temperature"],
authorities: 100,
}); Different Authorities per Channel
To open a writer with different authorities on each channel, pass the authorities
parameter with a list of integers. This list must be the same length as the number of
channels in the writer.
writer = client.open_writer(
start=sy.TimeStamp.now(),
channels=["time", "temperature"],
authorities=[100, 200],
) const writer = await client.openWriter({
start: TimeStamp.now(),
channels: ["time", "temperature"],
authorities: [100, 200],
}); Adjusting Authority After Open
To change the authority of a writer during operation, use the set_authority
# Set the authority on all channels
writer.set_authority(200)
# Set the authority on specific channels
writer.set_authority({
"time": 150,
"temperature": 250,
}) // Set the authority on all channels
await writer.setAuthority(200);
// Set the authority on specific channels
await writer.setAuthority({
time: 150,
temperature: 250,
}); Here’s a complete example showing dynamic authority changes during a write session:
with client.open_writer(
start=sy.TimeStamp.now(),
channels=["time", "temperature"],
authorities=100,
) as writer:
# Start with low authority
writer.write({"time": sy.TimeStamp.now(), "temperature": 25.0})
# Increase authority to take control from other writers
writer.set_authority(200)
writer.write({"time": sy.TimeStamp.now(), "temperature": 26.0})
# Release control by lowering authority
writer.set_authority(50) const writer = await client.openWriter({
start: TimeStamp.now(),
channels: ["time", "temperature"],
authorities: 100,
});
try {
// Start with low authority
await writer.write({ time: TimeStamp.now(), temperature: 25.0 });
// Increase authority to take control from other writers
await writer.setAuthority(200);
await writer.write({ time: TimeStamp.now(), temperature: 26.0 });
// Release control by lowering authority
await writer.setAuthority(50);
} finally {
await writer.close();
}