Skip to content

Commit b3e89c0

Browse files
rakhiagrRakhi Agrawal
and
Rakhi Agrawal
authored
Add shadow write support at BaseVersionedAspectResource and BaseAspec… (#535)
* Add shadow write support at BaseVersionedAspectResource and BaseAspectV2Resourc * Default null * Default null and add to delete * Checkstyle --------- Co-authored-by: Rakhi Agrawal <rakagrawal@linkedin.com>
1 parent 28d987f commit b3e89c0

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141
/**
42-
* This resource is intended to be used as top level resousce, instead of a sub resource.
42+
* This resource is intended to be used as top level resource, instead of a sub resource.
4343
* For sub-resource please use {@link BaseVersionedAspectResource}
4444
*
4545
* @param <URN> must be a valid {@link Urn} type
@@ -78,6 +78,13 @@ protected BaseRestliAuditor getAuditor() {
7878
@Nonnull
7979
protected abstract BaseLocalDAO<ASPECT_UNION, URN> getLocalDAO();
8080

81+
/**
82+
* Returns {@link BaseLocalDAO} for shadowing the aspect.
83+
*/
84+
protected BaseLocalDAO<ASPECT_UNION, URN> getLocalShadowDAO() {
85+
return null;
86+
}
87+
8188
/**
8289
* Get the ASPECT associated with URN.
8390
*/
@@ -112,6 +119,10 @@ public Task<CreateResponse> create(@Nonnull URN urn, @Nonnull ASPECT aspect) {
112119
return RestliUtils.toTask(() -> {
113120
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
114121
getLocalDAO().add(urn, aspect, auditStamp);
122+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
123+
if (shadowLocalDao != null) {
124+
shadowLocalDao.add(urn, aspect, auditStamp);
125+
}
115126
return new CreateResponse(HttpStatus.S_201_CREATED);
116127
});
117128
}
@@ -123,6 +134,10 @@ public Task<CreateResponse> createWithTracking(@Nonnull URN urn, @Nonnull ASPECT
123134
return RestliUtils.toTask(() -> {
124135
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
125136
getLocalDAO().add(urn, aspect, auditStamp, trackingContext, ingestionParams);
137+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
138+
if (shadowLocalDao != null) {
139+
shadowLocalDao.add(urn, aspect, auditStamp, trackingContext, ingestionParams);
140+
}
126141
return new CreateResponse(HttpStatus.S_201_CREATED);
127142
});
128143
}
@@ -138,6 +153,10 @@ public Task<CreateKVResponse<URN, ASPECT>> createAndGet(@Nonnull URN urn,
138153
return RestliUtils.toTask(() -> {
139154
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
140155
final ASPECT newValue = getLocalDAO().add(urn, _aspectClass, createLambda, auditStamp);
156+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
157+
if (shadowLocalDao != null) {
158+
shadowLocalDao.add(urn, _aspectClass, createLambda, auditStamp);
159+
}
141160
return new CreateKVResponse<>(urn, newValue);
142161
});
143162
}
@@ -153,6 +172,10 @@ public Task<UpdateResponse> delete(@Nonnull URN urn) {
153172
return RestliUtils.toTask(() -> {
154173
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
155174
getLocalDAO().delete(urn, this._aspectClass, auditStamp);
175+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
176+
if (shadowLocalDao != null) {
177+
shadowLocalDao.delete(urn, this._aspectClass, auditStamp);
178+
}
156179
return new UpdateResponse(HttpStatus.S_200_OK);
157180
});
158181
}

restli-resources/src/main/java/com/linkedin/metadata/restli/BaseVersionedAspectResource.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ protected BaseRestliAuditor getAuditor() {
7171
@Nonnull
7272
protected abstract BaseLocalDAO<ASPECT_UNION, URN> getLocalDAO();
7373

74+
/**
75+
* Returns {@link BaseLocalDAO} for shadowing the aspect.
76+
*/
77+
protected BaseLocalDAO<ASPECT_UNION, URN> getLocalShadowDAO() {
78+
return null;
79+
}
80+
7481
/**
7582
* Constructs an entity-specific {@link Urn} based on the entity's {@link PathKeys}.
7683
*/
@@ -109,6 +116,10 @@ public Task<CreateResponse> create(@Nonnull ASPECT aspect) {
109116
final URN urn = getUrn(getContext().getPathKeys());
110117
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
111118
getLocalDAO().add(urn, aspect, auditStamp);
119+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
120+
if (shadowLocalDao != null) {
121+
shadowLocalDao.add(urn, aspect, auditStamp);
122+
}
112123
return new CreateResponse(HttpStatus.S_201_CREATED);
113124
});
114125
}
@@ -125,6 +136,10 @@ public Task<UpdateResponse> delete() {
125136
final URN urn = getUrn(getContext().getPathKeys());
126137
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
127138
getLocalDAO().delete(urn, this._aspectClass, auditStamp);
139+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
140+
if (shadowLocalDao != null) {
141+
shadowLocalDao.delete(urn, this._aspectClass, auditStamp);
142+
}
128143
return new UpdateResponse(HttpStatus.S_200_OK);
129144
});
130145
}
@@ -139,6 +154,10 @@ public Task<CreateResponse> create(@Nonnull Class<ASPECT> aspectClass,
139154
final URN urn = getUrn(getContext().getPathKeys());
140155
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
141156
getLocalDAO().add(urn, aspectClass, createLambda, auditStamp);
157+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
158+
if (shadowLocalDao != null) {
159+
shadowLocalDao.add(urn, aspectClass, createLambda, auditStamp);
160+
}
142161
return new CreateResponse(HttpStatus.S_201_CREATED);
143162
});
144163
}
@@ -156,6 +175,10 @@ public Task<CreateKVResponse<Long, ASPECT>> createAndGet(@Nonnull Class<ASPECT>
156175
final URN urn = getUrn(getContext().getPathKeys());
157176
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
158177
final ASPECT newValue = getLocalDAO().add(urn, aspectClass, createLambda, auditStamp);
178+
BaseLocalDAO<ASPECT_UNION, URN> shadowLocalDao = getLocalShadowDAO();
179+
if (shadowLocalDao != null) {
180+
shadowLocalDao.add(urn, aspectClass, createLambda, auditStamp);
181+
}
159182
return new CreateKVResponse<>(LATEST_VERSION, newValue);
160183
});
161184
}

0 commit comments

Comments
 (0)