Skip to content

Commit b9a4a20

Browse files
update backgroud read endpoint refresh flow (Azure#24969)
### Packages impacted by this PR @azure/cosmos ### Issues associated with this PR 22726 ### Describe the problem that is addressed by this PR This pull request aims to correct the flow of the update read endpoint within the background refresh thread. Previously, it was retrieving results from the database write endpoint. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ Yes ### Provide a list of related PRs _(if any)_ Azure#24296 ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Manik Khandelwal <mkhandelwal@microsoft.com>
1 parent 5142f2a commit b9a4a20

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

sdk/cosmosdb/cosmos/src/globalEndpointManager.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import { OperationType, ResourceType, isReadRequest } from "./common";
44
import { CosmosClientOptions } from "./CosmosClientOptions";
55
import { Location, DatabaseAccount } from "./documents";
6-
import { Constants, RequestOptions } from "./index";
6+
import { RequestOptions } from "./index";
7+
import { Constants } from "./common/constants";
78
import { ResourceResponse } from "./request";
89

910
/**
@@ -181,7 +182,7 @@ export class GlobalEndpointManager {
181182
this.writeableLocations.push(location);
182183
}
183184
}
184-
for (const location of databaseAccount.writableLocations) {
185+
for (const location of databaseAccount.readableLocations) {
185186
const existingLocation = this.readableLocations.find((loc) => loc.name === location.name);
186187
if (!existingLocation) {
187188
this.readableLocations.push(location);
@@ -229,8 +230,9 @@ export class GlobalEndpointManager {
229230
loc &&
230231
now - loc.lastUnavailabilityTimestampInMs >= Constants.LocationUnavailableExpirationTimeInMs
231232
) {
232-
return true;
233+
return false;
233234
}
235+
return true;
234236
});
235237
}
236238

sdk/cosmosdb/cosmos/test/public/functional/globalEndpointManager.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe("GlobalEndpointManager", function () {
7474
"https://test-eastus2.documents.azure.com:443/"
7575
);
7676
});
77+
7778
it("should allow you to pass a normalized preferred location", async function () {
7879
gem = new GlobalEndpointManager(
7980
{
@@ -99,6 +100,7 @@ describe("GlobalEndpointManager", function () {
99100
"https://test-eastus2.documents.azure.com:443/"
100101
);
101102
});
103+
102104
it("should resolve to endpoint when call made after server unavailability time", async function () {
103105
const clock: fakeTimers.InstalledClock = fakeTimers.install();
104106

@@ -119,25 +121,19 @@ describe("GlobalEndpointManager", function () {
119121
return response;
120122
}
121123
);
122-
124+
await gem.refreshEndpointList();
123125
await gem.markCurrentLocationUnavailableForRead(
124126
"https://test-westus2.documents.azure.com:443/"
125127
);
126-
assert.equal(
127-
await gem.resolveServiceEndpoint(ResourceType.item, OperationType.Read),
128-
"https://test.documents.azure.com:443/"
129-
);
128+
assert.equal(await gem.getReadEndpoint(), "https://test-eastus2.documents.azure.com:443/");
130129
clock.tick(locationUnavailabilityExpiratationTime);
131130
await gem.refreshEndpointList();
132-
assert.equal(
133-
await gem.resolveServiceEndpoint(ResourceType.item, OperationType.Read),
134-
"https://test-westus2.documents.azure.com:443/"
135-
);
131+
assert.equal(await gem.getReadEndpoint(), "https://test-westus2.documents.azure.com:443/");
136132
clock.uninstall();
137133
});
138134
});
139135

140-
describe("#markCurrentLocationUnavailableForRead", function () {
136+
describe("#markCurrentLocationUnavailable", function () {
141137
const gem = new GlobalEndpointManager(
142138
{
143139
endpoint: "https://test.documents.azure.com:443/",
@@ -157,16 +153,19 @@ describe("GlobalEndpointManager", function () {
157153
}
158154
);
159155

156+
beforeEach(async () => {
157+
await gem.refreshEndpointList();
158+
});
159+
160160
it("should mark the current location unavailable for read", async function () {
161161
// We don't block on init for database account calls
162162
await gem.markCurrentLocationUnavailableForRead(
163-
"https://test-westus2.documents.azure.com:443/"
163+
"https://test-eastus2.documents.azure.com:443/"
164164
);
165-
166165
/* As we have marked current location unavailable for read,
167166
next read should go to the next location or default endpoint
168167
*/
169-
assert.equal(await gem.getReadEndpoint(), "https://test.documents.azure.com:443/");
168+
assert.equal(await gem.getReadEndpoint(), "https://test-westus2.documents.azure.com:443/");
170169
});
171170
it("should mark the current location unavailable for write", async function () {
172171
// We don't block on init for database account calls

0 commit comments

Comments
 (0)