-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Event Hubs] Implement PartitionManager methods #4538
Merged
ShivangiReja
merged 6 commits into
Azure:master
from
ShivangiReja:implement_PartitionManager
Jul 30, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac30216
[Event Hubs] Implement PartitionManager methods
ShivangiReja 7283f2d
Update tests
ShivangiReja b75d1d9
Address comments
ShivangiReja c7de194
Update sdk/eventhub/event-hubs/test/eventProcessor.spec.ts
ShivangiReja d880b4b
Address comments
ShivangiReja 92d5898
Merge into master
ShivangiReja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { PartitionManager, PartitionOwnership } from "./eventProcessor"; | ||
import { Checkpoint } from "./checkpointManager"; | ||
import { generate_uuid } from "rhea-promise"; | ||
|
||
/** | ||
* A simple in-memory implementation of a `PartitionManager` | ||
* @class | ||
*/ | ||
export class InMemoryPartitionManager implements PartitionManager { | ||
private _partitionOwnershipMap: Map<string, PartitionOwnership> = new Map(); | ||
|
||
/** | ||
* Get the list of all existing partition ownership from the underlying data store. Could return empty | ||
* results if there are is no existing ownership information. | ||
* | ||
* @param eventHubName The event hub name. | ||
* @param consumerGroupName The consumer group name. | ||
* @return Partition ownership details of all the partitions that have/had an owner.. | ||
*/ | ||
async listOwnerships( | ||
eventHubName: string, | ||
consumerGroupName: string | ||
): Promise<PartitionOwnership[]> { | ||
return Array.from(this._partitionOwnershipMap.values()); | ||
} | ||
|
||
/** | ||
* Claim ownership of a list of partitions. This will return the list of partitions that were owned | ||
* successfully. | ||
* | ||
* @param partitionOwnerships The list of partition ownerships this instance is claiming to own. | ||
* @return A list partitions this instance successfully claimed ownership. | ||
*/ | ||
async claimOwnerships(partitionOwnerships: PartitionOwnership[]): Promise<PartitionOwnership[]> { | ||
for (const partitionOwnership of partitionOwnerships) { | ||
if (!this._partitionOwnershipMap.has(partitionOwnership.partitionId)) { | ||
partitionOwnership.eTag = generate_uuid(); | ||
this._partitionOwnershipMap.set(partitionOwnership.partitionId, partitionOwnership); | ||
} | ||
} | ||
return partitionOwnerships; | ||
} | ||
|
||
/** | ||
* Updates the checkpoint in the data store for a partition. | ||
* | ||
* @param checkpoint The checkpoint. | ||
* @return Promise<void> | ||
*/ | ||
async updateCheckpoint(checkpoint: Checkpoint): Promise<void> { | ||
const partitionOwnership = this._partitionOwnershipMap.get(checkpoint.partitionId); | ||
if (partitionOwnership) { | ||
partitionOwnership.sequenceNumber = checkpoint.sequenceNumber; | ||
partitionOwnership.offset = checkpoint.offset; | ||
partitionOwnership.eTag = generate_uuid(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something all languages are exposing? I don't remember seeing it in our API design, that
close()
takes a reason. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed API for javascript, here it takes CloseReason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@conniey We brought that up on Monday too, because we were curious how Java would know why the subscription was closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also wonder what the user could do differently with that reason (ie. user shutdown vs stolen)? I mean, we log it in the EventConsumer but it is not propagated out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory if it was a shutdown they could checkpoint one last time, whereas if it were stolen they wouldn’t be able to update the checkpoint.