pub struct BigTableClientImpl { /* private fields */ }
Expand description
Wrapper for the BigTable connection
Implementations§
Source§impl BigTableClientImpl
impl BigTableClientImpl
Connect to a BigTable storage model.
BigTable is available via the Google Console, and is a schema less storage system.
The db_dsn
string should be in the form of
grpc://{BigTableEndpoint}
The settings contains the table_name
which is the GRPC path to the data.
(e.g. projects/{project_id}/instances/{instance_id}/tables/{table_id}
)
where:
BigTableEndpoint is the endpoint domain to use (the default is bigtable.googleapis.com
) See
BigTable Endpoints for more details.
project-id is the Google project identifier (see the Google developer console (e.g. ‘autopush-dev’))
instance-id is the Google project instance, (see the Google developer console (e.g. ‘development-1’))
table_id is the Table Name (e.g. ‘autopush’)
This will automatically bring in the default credentials specified by the GOOGLE_APPLICATION_CREDENTIALS
environment variable.
NOTE: Some configurations may look for the default credential file (pointed to by
GOOGLE_APPLICATION_CREDENTIALS
) to be stored in
$HOME/.config/gcloud/application_default_credentials.json
)
pub fn new(metrics: Arc<StatsdClient>, settings: &DbSettings) -> DbResult<Self>
Sourcepub fn spawn_sweeper(&self, interval: Duration)
pub fn spawn_sweeper(&self, interval: Duration)
Spawn a task to periodically evict idle connections
Trait Implementations§
Source§impl Clone for BigTableClientImpl
impl Clone for BigTableClientImpl
Source§fn clone(&self) -> BigTableClientImpl
fn clone(&self) -> BigTableClientImpl
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl DbClient for BigTableClientImpl
impl DbClient for BigTableClientImpl
Source§fn add_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
add user to the database
Source§fn update_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 mut User,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 mut User,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
BigTable doesn’t really have the concept of an “update”. You simply write the data and the individual cells create a new version. Depending on the garbage collection rules for the family, these can either persist or be automatically deleted.
NOTE: This function updates the key ROUTER records for a given UAID. It does this by
calling BigTableClientImpl::user_to_row which creates a new row with new cell.timestamp
values set
to now + MAX_ROUTER_TTL
. This function is called by mobile during the daily
[autoendpoint::routes::update_token_route] handling, and by desktop
[autoconnect-ws-sm::get_or_create_user]which is called during the
HELLO` handler. This should be enough to ensure that the ROUTER records
are properly refreshed for “lively” clients.
NOTE: There is some, very small, potential risk that a desktop client that can somehow remain connected the duration of MAX_ROUTER_TTL, may be dropped as not being “lively”.
Source§fn add_channels<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
channels: HashSet<Uuid>,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add_channels<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
channels: HashSet<Uuid>,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Add channels in bulk (used mostly during migration)
Source§fn remove_channel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
channel_id: &'life2 Uuid,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn remove_channel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
channel_id: &'life2 Uuid,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Delete the channel. Does not delete its associated pending messages.
Source§fn remove_node_id<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
_node_id: &'life2 str,
_connected_at: u64,
version: &'life3 Option<Uuid>,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn remove_node_id<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
_node_id: &'life2 str,
_connected_at: u64,
version: &'life3 Option<Uuid>,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Remove the node_id
Source§fn save_message<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
message: Notification,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_message<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
message: Notification,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Write the notification to storage.
Source§fn save_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
messages: Vec<Notification>,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
messages: Vec<Notification>,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Save a batch of messages to the database.
Currently just iterating through the list and saving one at a time. There’s a bulk way to save messages, but there are other considerations (e.g. mutation limits)
Source§fn increment_storage<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
timestamp: u64,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn increment_storage<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
timestamp: u64,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Set the current_timestamp
in the meta record for this user agent.
This is a bit different for BigTable. Field expiration (technically cell expiration) is determined by the lifetime assigned to the cell once it hits a given date. That means you can’t really extend a lifetime by adjusting a single field. You’d have to adjust all the cells that are in the family. So, we’re not going to do expiration that way.
That leaves the meta “current_timestamp” field. We do not purge ACK’d records,
instead we presume that the TTL will kill them off eventually. On reads, we use
the current_timestamp
to determine what records to return, since we return
records with timestamps later than current_timestamp
.
Source§fn remove_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
chidmessageid: &'life2 str,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn remove_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
chidmessageid: &'life2 str,
) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Delete the notification from storage.
Source§fn fetch_topic_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
limit: usize,
) -> Pin<Box<dyn Future<Output = DbResult<FetchMessageResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_topic_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
limit: usize,
) -> Pin<Box<dyn Future<Output = DbResult<FetchMessageResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Return limit
pending messages from storage. limit=0
for all messages.
Source§fn fetch_timestamp_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
timestamp: Option<u64>,
limit: usize,
) -> Pin<Box<dyn Future<Output = DbResult<FetchMessageResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_timestamp_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
uaid: &'life1 Uuid,
timestamp: Option<u64>,
limit: usize,
) -> Pin<Box<dyn Future<Output = DbResult<FetchMessageResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Return limit
messages pending for a UAID that have a sortkey_timestamp after
what’s specified. limit=0
for all messages.
Source§fn router_table_exists<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn router_table_exists<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns true, because there’s only one table in BigTable. We divide things up
by family
.
Source§fn message_table_exists<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn message_table_exists<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DbResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns true, because there’s only one table in BigTable. We divide things up
by family
.