Skip to content

Commit

Permalink
Iterating.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMcFelix committed May 21, 2024
1 parent 6a3f486 commit cdf6025
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ progenitor::generate_api!(
ReifiedVpcRoute = omicron_common::api::internal::shared::ReifiedVpcRoute,
ReifiedVpcRouteSet = omicron_common::api::internal::shared::ReifiedVpcRouteSet,
RouterTarget = omicron_common::api::internal::shared::RouterTarget,
RouterVersion = omicron_common::api::internal::shared::RouterVersion,
SourceNatConfig = omicron_common::api::internal::shared::SourceNatConfig,
Vni = omicron_common::api::external::Vni,
NetworkInterface = omicron_common::api::internal::shared::NetworkInterface,
Expand Down
52 changes: 52 additions & 0 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,58 @@ impl DataStore {

Ok(out)
}

/// Trigger an RPW version bump on a single VPC router in response
/// to CRUD operations on individual routes.
pub async fn vpc_router_increment_rpw_version(
&self,
opctx: &OpContext,
authz_router: &authz::VpcRouter,
) -> UpdateResult<()> {
opctx.authorize(authz::Action::Modify, authz_router).await?;

use db::schema::vpc_router::dsl;
diesel::update(dsl::vpc_router)
.filter(dsl::time_deleted.is_null())
.filter(dsl::id.eq(authz_router.id()))
.set(dsl::resolved_version.eq(dsl::resolved_version + 1))
.execute_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| {
public_error_from_diesel(
e,
ErrorHandler::NotFoundByResource(authz_router),
)
})?;

Ok(())
}

/// Trigger an RPW version bump on all routers within a VPC in
/// response to changes to named entities (e.g., subnets, instances).
pub async fn vpc_increment_rpw_version(
&self,
opctx: &OpContext,
authz_vpc: &authz::Vpc,
) -> UpdateResult<()> {
opctx.authorize(authz::Action::CreateChild, authz_vpc).await?;

use db::schema::vpc_router::dsl;
diesel::update(dsl::vpc_router)
.filter(dsl::time_deleted.is_null())
.filter(dsl::vpc_id.eq(authz_vpc.id()))
.set(dsl::resolved_version.eq(dsl::resolved_version + 1))
.execute_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| {
public_error_from_diesel(
e,
ErrorHandler::NotFoundByResource(authz_vpc),
)
})?;

Ok(())
}
}

#[cfg(test)]
Expand Down
11 changes: 5 additions & 6 deletions nexus/src/app/background/vpc_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl BackgroundTask for VpcRouteManager {
let Some(db_router) = db_routers.get(&set.id) else {
// The sled wants to know about rules for a VPC
// subnet with no custom router set. Send them
// the empty list, unset its table version.
// the empty list, and unset its table version.
set_rules(set.id, None, HashSet::new());
continue;
};
Expand All @@ -203,12 +203,11 @@ impl BackgroundTask for VpcRouteManager {
router_id,
};

// Only attempt to resolve/push a ruleset if we have a different
// router ID than the sled, or a higher version number.
// Only attempt to resolve/push a ruleset if we have a
// different router ID than the sled, or a higher version
// number.
match &set.version {
Some(v)
if v.router_id == router_id
&& v.generation >= version.generation =>
Some(v) if !v.is_replaced_by(&version) =>
{
continue;
}
Expand Down

0 comments on commit cdf6025

Please sign in to comment.