Skip to content

Commit

Permalink
[CCR] Open index after unfollowing leader (#29887)
Browse files Browse the repository at this point in the history
* Open index after unfollowing leader, fix some variable names

* Fix typo

* Add comment
  • Loading branch information
jen-huang committed Feb 4, 2019
1 parent fad4473 commit ebc2610
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export const pauseFollowerIndex = (id) => (
}

if (response.itemsPaused.length) {
const hasMultipleDelete = response.itemsPaused.length > 1;
const hasMultiplePaused = response.itemsPaused.length > 1;

const successMessage = hasMultipleDelete
const successMessage = hasMultiplePaused
? i18n.translate('xpack.crossClusterReplication.followerIndex.pauseAction.successMultipleNotificationTitle', {
defaultMessage: `{count} follower indices were paused`,
values: { count: response.itemsPaused.length },
Expand Down Expand Up @@ -160,9 +160,9 @@ export const resumeFollowerIndex = (id) => (
}

if (response.itemsResumed.length) {
const hasMultipleDelete = response.itemsResumed.length > 1;
const hasMultipleResumed = response.itemsResumed.length > 1;

const successMessage = hasMultipleDelete
const successMessage = hasMultipleResumed
? i18n.translate('xpack.crossClusterReplication.followerIndex.resumeAction.successMultipleNotificationTitle', {
defaultMessage: `{count} follower indices were resumed`,
values: { count: response.itemsResumed.length },
Expand Down Expand Up @@ -210,9 +210,9 @@ export const unfollowLeaderIndex = (id) => (
}

if (response.itemsUnfollowed.length) {
const hasMultipleDelete = response.itemsUnfollowed.length > 1;
const hasMultipleUnfollow = response.itemsUnfollowed.length > 1;

const successMessage = hasMultipleDelete
const successMessage = hasMultipleUnfollow
? i18n.translate('xpack.crossClusterReplication.followerIndex.unfollowAction.successMultipleNotificationTitle', {
defaultMessage: `Leader indices of {count} follower indices were unfollowed`,
values: { count: response.itemsUnfollowed.length },
Expand All @@ -225,6 +225,22 @@ export const unfollowLeaderIndex = (id) => (
toastNotifications.addSuccess(successMessage);
}

if (response.itemsNotOpen.length) {
const hasMultipleNotOpen = response.itemsNotOpen.length > 1;

const warningMessage = hasMultipleNotOpen
? i18n.translate('xpack.crossClusterReplication.followerIndex.unfollowAction.notOpenWarningMultipleNotificationTitle', {
defaultMessage: `{count} indices could not be re-opened`,
values: { count: response.itemsNotOpen.length },
})
: i18n.translate('xpack.crossClusterReplication.followerIndex.unfollowAction.notOpenWarningSingleNotificationTitle', {
defaultMessage: `Index '{name}' could not be re-opened`,
values: { name: response.itemsNotOpen[0] },
});

toastNotifications.addWarning(warningMessage);
}

// If we've just unfollowed a follower index we were looking at, we need to close the panel.
const followerIndexId = getSelectedFollowerIndexId('detail')(getState());
if (response.itemsUnfollowed.includes(followerIndexId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const registerFollowerIndexRoutes = (server) => {
const ids = id.split(',');

const itemsUnfollowed = [];
const itemsNotOpen = [];
const errors = [];

await Promise.all(ids.map(async (_id) => {
Expand All @@ -274,6 +275,14 @@ export const registerFollowerIndexRoutes = (server) => {
// Unfollow leader
await callWithRequest('ccr.unfollowLeaderIndex', { id: _id });

// Try to re-open the index, store failures in a separate array to surface warnings in the UI
// This will allow users to query their index normally after unfollowing
try {
await callWithRequest('indices.open', { index: _id });
} catch (e) {
itemsNotOpen.push(_id);
}

// Push success
itemsUnfollowed.push(_id);
} catch (err) {
Expand All @@ -287,6 +296,7 @@ export const registerFollowerIndexRoutes = (server) => {

return {
itemsUnfollowed,
itemsNotOpen,
errors
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ describe('[CCR API Routes] Follower Index', () => {
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });

const response = await routeHandler({ params: { id: '1' } });

Expand All @@ -264,6 +265,9 @@ describe('[CCR API Routes] Follower Index', () => {
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });
setHttpRequestResponse(null, { acknowledge: true });

const response = await routeHandler({ params: { id: '1,2,3' } });

Expand Down

0 comments on commit ebc2610

Please sign in to comment.