Skip to content

Commit

Permalink
[Code] adjust the orders of delete steps to avoid long lang server in…
Browse files Browse the repository at this point in the history
…itialization stage (#43893) (#44042)
  • Loading branch information
mw-ding authored Aug 26, 2019
1 parent 13c2d4a commit c8486f0
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions x-pack/legacy/plugins/code/server/queue/delete_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,45 @@ export class DeleteWorker extends AbstractWorker {
public async executeJob(job: Job) {
const { uri } = job.payload;

// 1. Cancel running workers
await this.cancellationService.cancelCloneJob(uri, CancellationReason.REPOSITORY_DELETE);
await this.cancellationService.cancelUpdateJob(uri, CancellationReason.REPOSITORY_DELETE);
await this.cancellationService.cancelIndexJob(uri, CancellationReason.REPOSITORY_DELETE);

// 2. Delete git repository and all related data.
const repoService = this.repoServiceFactory.newInstance(
this.serverOptions.repoPath,
this.serverOptions.credsPath,
this.log,
this.serverOptions.security.enableGitCertCheck
);

const deleteWorkspacePromise = this.deletePromiseWrapper(
this.lspService.deleteWorkspace(uri),
'workspace',
uri
);

// 3. Delete ES indices and aliases
const deleteSymbolESIndexPromise = this.deletePromiseWrapper(
this.client.indices.delete({ index: `${SymbolIndexName(uri)}*` }),
'symbol ES index',
uri
);
try {
// 1. Cancel running clone and update workers
await this.cancellationService.cancelCloneJob(uri, CancellationReason.REPOSITORY_DELETE);
await this.cancellationService.cancelUpdateJob(uri, CancellationReason.REPOSITORY_DELETE);

// 2. Delete workspace and index workers. Since the indexing could be
// hanging in the initialization stage, we should delete the workspace
// to cancel it in the meantime.
const deleteWorkspacePromise = this.deletePromiseWrapper(
this.lspService.deleteWorkspace(uri),
'workspace',
uri
);
const indexJobCancelPromise = this.cancellationService.cancelIndexJob(
uri,
CancellationReason.REPOSITORY_DELETE
);
await Promise.all([deleteWorkspacePromise, indexJobCancelPromise]);

const deleteReferenceESIndexPromise = this.deletePromiseWrapper(
this.client.indices.delete({ index: `${ReferenceIndexName(uri)}*` }),
'reference ES index',
uri
);
// 3. Delete ES indices and aliases
const deleteSymbolESIndexPromise = this.deletePromiseWrapper(
this.client.indices.delete({ index: `${SymbolIndexName(uri)}*` }),
'symbol ES index',
uri
);

try {
await Promise.all([
deleteWorkspacePromise,
deleteSymbolESIndexPromise,
deleteReferenceESIndexPromise,
]);
const deleteReferenceESIndexPromise = this.deletePromiseWrapper(
this.client.indices.delete({ index: `${ReferenceIndexName(uri)}*` }),
'reference ES index',
uri
);
await Promise.all([deleteSymbolESIndexPromise, deleteReferenceESIndexPromise]);

const repoService = this.repoServiceFactory.newInstance(
this.serverOptions.repoPath,
this.serverOptions.credsPath,
this.log,
this.serverOptions.security.enableGitCertCheck
);
this.gitOps.cleanRepo(uri);
await this.deletePromiseWrapper(repoService.remove(uri), 'git data', uri);

Expand Down

0 comments on commit c8486f0

Please sign in to comment.