Skip to content
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

Codenvy-1127 docker instance implementation that that limits number of simultaneous container commits on the same node. #1166

Merged
merged 10 commits into from
Nov 18, 2016

Conversation

mshaposhnik
Copy link
Contributor

@mshaposhnik mshaposhnik commented Nov 16, 2016

What does this PR do?

Adds docker instance implementation that limits number of simultaneous container commits on the same node at the same time.

What issues does this PR fix or reference?

Fixes #1127

Previous Behavior

Multiple container commits may be possible on same node.

New Behavior

Commits are one-by-one

Tests written?

Docs requirements?

None

semaphore = newSemaphore;
}
}
System.out.println("~~~~~~~~~~~~" + semaphore);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it debug info ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah

@mshaposhnik mshaposhnik changed the title Codenvy-1127 docker instance implementation that prevents multiple container commits on the same node at the same time. Codenvy-1127 docker instance implementation that that limits number of simultaneous container commits on the same node at the same time. Nov 18, 2016
@mshaposhnik mshaposhnik changed the title Codenvy-1127 docker instance implementation that that limits number of simultaneous container commits on the same node at the same time. Codenvy-1127 docker instance implementation that that limits number of simultaneous container commits on the same node. Nov 18, 2016
nodeSemaphore.acquire();
super.commitContainer(repository, tag);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to throw smthng here, but only IO is possible. WDYT ?

Copy link
Contributor

Choose a reason for hiding this comment

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

throw new IOException(e) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

executor.execute(() -> performCommit(repo3, TAG));

// thread #3 should wait - semaphore is red
verify(dockerConnectorMock, never()).commit(Matchers.argThat(new CommitParamsMatcher(repo3)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that timeout is needed here, otherwise there is no guarantee that 3rd thread was started. Also it would be nice to verify that Instance.commit is called

executor.execute(() -> performCommit(repo1, TAG));
executor.execute(() -> performCommit(repo2, TAG));
waitingAnswer1.waitAnswerCall(1, TimeUnit.SECONDS);
waitingAnswer2.waitAnswerCall(1, TimeUnit.SECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

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

repo2 also won't commit until repo1 commit is finished. Maybe remove 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.

It will - i set permits to 2

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, I missed this



@Test
public void shouldBeAbleToCommitSimultaneously() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test for different nodes

super.commitContainer(repository, tag);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

new IOException(e, e.getLocalizedMessage());?

*/
public class HostedDockerInstance extends DockerInstance {

private static final Map<String, Semaphore> SEMAPHORES = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't say that CONSTANT_CASE is the right one for the mutable value, see examples

… Avoid of concurrent snapshots on same node.
Thread.sleep(200); //to allow thread # 3 start

// thread #3 commit executed too
verify(dockerInstance).commitContainer(eq(repo3), eq(TAG));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use mockito times instead of Thread.sleep here, it can boost test

…Y-1127; Avoid of concurrent snapshots on same node.
@mshaposhnik mshaposhnik merged commit 9ad0051 into master Nov 18, 2016
@mshaposhnik mshaposhnik deleted the CODENVY-1127 branch November 18, 2016 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid of concurrent snapshots on same node.
4 participants