Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Introduce persistence layer for the broker #106

Merged
merged 7 commits into from
Jan 8, 2018

Conversation

Asitha
Copy link
Contributor

@Asitha Asitha commented Dec 22, 2017

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.

Purpose of this feature is to introduce persistence of Messages, Exchanges, Queues and Bindings so that messages won't get lost on server failure.

Resolves #24, Resolves #105, Resolves #93, Resolves #79, Resolves #69

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

With this PR we are introducing RDBMS based message persistence layer to persist Messages, Exchanges, Queues and Bindings

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

Following key improvements are done

  • Introduce RDBMS based persistence support. (Added built in Derby database and script for MySQL)
  • Re-queued messages delivered first when dequeuing from the queue.
  • Restore persisted states when restarting the broker.
  • Initial implementation of message persistence operation cancellation as an optimisation.

User stories

Summary of user stories addressed by this change>

N/A

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

RDBMS based persistent layer. Supports standard SQL based DBMS

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Yes

Security checks

No

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

N/A

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

@Asitha Asitha requested a review from a5anka December 22, 2017 06:24
@Asitha Asitha self-assigned this Dec 22, 2017
@Asitha Asitha force-pushed the message-persistence branch 4 times, most recently from a32b55d to bb4d246 Compare December 28, 2017 06:04
@Asitha Asitha force-pushed the message-persistence branch from bb4d246 to 6cefbd9 Compare January 2, 2018 04:12
wso2-jenkins-bot added a commit that referenced this pull request Jan 3, 2018
@Asitha Asitha force-pushed the message-persistence branch 2 times, most recently from 0489b8c to b704394 Compare January 4, 2018 13:06
warunalakshitha pushed a commit to warunalakshitha/message-broker that referenced this pull request Jan 4, 2018
warunalakshitha pushed a commit to warunalakshitha/message-broker that referenced this pull request Jan 4, 2018
warunalakshitha pushed a commit to warunalakshitha/message-broker that referenced this pull request Jan 4, 2018
warunalakshitha pushed a commit to warunalakshitha/message-broker that referenced this pull request Jan 4, 2018
@Asitha Asitha force-pushed the message-persistence branch 6 times, most recently from 0a5b8af to 4cee110 Compare January 8, 2018 05:30
}

public ByteBuf getRawMetadata() {
return rawMetadata;
public boolean hasAttachedQueues() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use a single word denote the attached queues (attached or owned)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used the word attached in all the places

@@ -56,15 +55,15 @@ public void basicPublishReceived(ShortString routingKey, ShortString exchangeNam

/**
* Add the header frame that gives the relevant metadata for the given message.
*
* @param rawMetadata unprocessed raw metadata {@link ByteBuf}
* @param headers protocol specific headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the spacing issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

*
* @param rawMetadata unprocessed raw metadata {@link ByteBuf}
* @param headers protocol specific headers
* @param properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define what the properties mean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@Asitha Asitha force-pushed the message-persistence branch from 4cee110 to 84a2c1f Compare January 8, 2018 06:37

void bind(Queue queue, String routingKey, FieldTable arguments) throws BrokerException;
public BindingDao getBindingDao() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is unused. Maybe we can get rid of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method removed.

previousTimestamp = ts;
long id = (ts - REFERENCE_START) * 256L * 1024L + instanceId * 1024L + offset;
if (previousId == id) {
throw new RuntimeException("duplicate ids detected. This should never happen");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use "Duplicate"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Asitha Asitha force-pushed the message-persistence branch 2 times, most recently from d0928c3 to 8527888 Compare January 8, 2018 08:20
}
// Unique queues can be empty due unmatching selectors.
if (!uniqueQueues.isEmpty()) {
boolean published = publishToQueues(message, uniqueQueues);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a local variable for this? Can't directly use it on if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code segment.

@Asitha Asitha force-pushed the message-persistence branch from 8527888 to 91baa09 Compare January 8, 2018 09:07

if (passive && queueHandler == null) {
throw new BrokerException("QueueHandler [ " + queueName + " ] doesn't exists. Passive parameter " +
"is set, hence not creating the queue.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ should precede here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@Asitha Asitha force-pushed the message-persistence branch 5 times, most recently from 38f5944 to 7d54046 Compare January 8, 2018 09:47
<!--<classes>-->
<!--<class name="org.wso2.messaging.integration.QueueConsumerTest"/>-->
<!--</classes>-->
<!--</test>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove this part since we have it above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

<fileSet>
<directory>target/database/</directory>
<outputDirectory>database</outputDirectory>
<fileMode>755</fileMode>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set the file mode to 755?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 644

@Asitha Asitha force-pushed the message-persistence branch 2 times, most recently from d124b2b to 3579d50 Compare January 8, 2018 12:07
Asitha added 6 commits January 8, 2018 17:43
- Implement database backed queue with message persist and delete operations.
- Update broker metadata implementation with FieldTables to
  handle message properties and headers.

- Implement database backed queue message restoration at broker
  startup.
Send an error to the client and log the exception when the client request
to close a consumer with an invalid consumer tag.
@Asitha Asitha force-pushed the message-persistence branch from 3579d50 to 7d407f0 Compare January 8, 2018 12:17
@Asitha Asitha merged commit 9bb85e1 into wso2-attic:master Jan 8, 2018
@a5anka a5anka added this to the 1.0.x-M7 milestone Jan 8, 2018
@Asitha Asitha deleted the message-persistence branch January 9, 2018 03:46
@wso2-attic wso2-attic deleted a comment from Asitha Jan 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants