Skip to content

Commit

Permalink
Handle conflicting traces when opening
Browse files Browse the repository at this point in the history
When opening a trace on the server results in a conflict, the client will try
reposting it with a different name until it succeeds or another error
occurs.

Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
  • Loading branch information
tahini committed May 26, 2020
1 parent a13523b commit 84fbc8d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions viewer-prototype/src/common/trace-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client';
import { Query } from 'tsp-typescript-client/lib/models/query/query';
import { injectable, inject } from 'inversify';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import { TspClientResponse } from 'tsp-typescript-client/lib/protocol/tsp-client-response';

@injectable()
export class TraceManager {
Expand Down Expand Up @@ -89,6 +90,27 @@ export class TraceManager {
this.addTrace(trace);
this.traceOpenedEmitter.fire(trace);
return trace;
} else if (trace && traceResponse.getStatusCode() === 409) {
// Repost with a suffix as long as there are conflicts
let handleConflict = async function(tspClient: TspClient, tryNb: number): Promise<TspClientResponse<Trace>> {
let suffix = '(' + tryNb + ')';
return await tspClient.openTrace(new Query({
'name': name + suffix,
'uri': tracePath
}))
}
let conflictResolutionResponse = traceResponse;
let i = 1;
while (conflictResolutionResponse.getStatusCode() === 409) {
conflictResolutionResponse = await handleConflict(this.tspClient, i);
i++;
}
const trace = conflictResolutionResponse.getModel()
if (trace && conflictResolutionResponse.isOk()) {
this.addTrace(trace);
this.traceOpenedEmitter.fire(trace);
return trace;
}
}
// TODO Handle trace open errors
return undefined;
Expand Down

0 comments on commit 84fbc8d

Please sign in to comment.