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

Change worskpace project files storage path #7844

Merged
merged 8 commits into from
Dec 22, 2017
Merged

Change worskpace project files storage path #7844

merged 8 commits into from
Dec 22, 2017

Conversation

mkuznyetsov
Copy link
Contributor

@mkuznyetsov mkuznyetsov commented Dec 12, 2017

What does this PR do?

  • Workspace projects are now stored in folders, named after their workspace id, rather than name,
    to prevent issues with workspace renaming. Applies to Docker infrastructure only.
  • Add migration, that would move workspace projects to their new location. Occurs on Che startup.
  • Added configuration property to enable/disable this migration.
  • Improved Workspace DAO/Manager to use pagination for methods, that return lists of workspaces

What issues does this PR fix or reference?

should fix #3574

Changelog

Workspace projects are stored in folders, named after their workspace ID (previously, after their workspace name

Release Notes

N/A

Docs PR

N/A

@benoitf benoitf added target/che6 status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/bug Outline of a bug - must adhere to the bug report template. labels Dec 12, 2017
@skabashnyuk
Copy link
Contributor

ci-test

@codenvy-ci
Copy link

@@ -42,6 +42,10 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Copy link
Contributor

@skabashnyuk skabashnyuk Dec 13, 2017

Choose a reason for hiding this comment

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

remove it

@@ -61,6 +74,11 @@ public void setUp() throws Exception {
oldWorkspacesRoot = Paths.get(workspacesRoot, "oldWorkspacesRoot").toString();
}

@AfterMethod
public void tearDown() throws Exception {
FileUtils.deleteDirectory(workspacesRootFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

IoUtil.deleteRecursive

}

public String getPathByName(String workspaceName) throws IOException {
public String getPathByName(String workspaceName, String workspaceNamespace) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this method

workspaceStoredByIdLocation,
StandardCopyOption.ATOMIC_MOVE);
LOG.info(
"Successfully workspace with id '{}' and name '{}'",
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this message more clear

workspaceManagerProvider
.get()
.getByNamespace(account.getName(), false)
Lists.newArrayList(
Copy link
Contributor

Choose a reason for hiding this comment

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

Too complex

@@ -48,7 +51,13 @@ public WorkspaceResourceUsageTracker(
throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final List<WorkspaceImpl> accountWorkspaces =
workspaceManagerProvider.get().getByNamespace(account.getName(), false);
Lists.newArrayList(
Copy link
Contributor

Choose a reason for hiding this comment

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

too complex

* Get all workspaces, and check if they are stored in workspacesMountPoint by their name, and
* migrate them, so they will be stored by id
*/
private void performWorkspaceLocationMigration() {

Choose a reason for hiding this comment

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

It is better to keep all the logic in a separate class.

@@ -225,7 +227,12 @@ public WorkspaceDto getByKey(
// TODO add maxItems & skipCount to manager

Choose a reason for hiding this comment

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

Looks like this todo is not needed anymore


assertEquals(new HashSet<>(found), new HashSet<>(asList(workspace1, workspace2)));
assertEquals(new HashSet<>(found.getItems()), new HashSet<>(asList(workspace1, workspace2)));

Choose a reason for hiding this comment

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

Are you going to add new tests for checking the new functionality?

workspace.getId(),
e.getLocalizedMessage());
}
;
Copy link
Member

Choose a reason for hiding this comment

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

Please check if this semicolon is needed here

remover.removeTemporaryWs();

verify(workspaceDao, times(COUNT_OF_WORKSPACES)).remove(anyString());
verify(workspaceDao, times(250)).remove(anyString());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to use constant here

@mkuznyetsov
Copy link
Contributor Author

ci-test

@codenvy-ci
Copy link

@@ -209,4 +231,9 @@ private void ensureExist(String path, String prop) throws IOException {
}
}
}

/**
* Get all workspaces, and check if they are stored in workspacesMountPoint by their name, and
Copy link
Member

Choose a reason for hiding this comment

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

Please check that this comment is located in correct place.

Signed-off-by: Oleksandr Garagatyi <ogaragat@redhat.com>
Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

Looks good. Few minor things left.

}
//
// @Test
// public void shouldMigrateOnlyWorkspacesWithOldLocation() throws Exception {

Choose a reason for hiding this comment

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

Please, fix commented test

workspace.getId(),
e.getLocalizedMessage());
}
;

Choose a reason for hiding this comment

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

@mkuznyetsov Please, take a look

@mkuznyetsov mkuznyetsov changed the title [WIP] Migrate workspace projects storage for Docker infrastructure Migrate workspace projects storage for Docker infrastructure Dec 20, 2017

/**
* Performs migration of projects that are stored for workspace in directories, named respectively
* by their names, to new
Copy link
Member

Choose a reason for hiding this comment

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

is something missing after to new?

workspaceStoredByNameLocation,
workspaceStoredByIdLocation,
StandardCopyOption.ATOMIC_MOVE);
LOG.info(
Copy link
Member

Choose a reason for hiding this comment

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

I'd change info level here to debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, stay with info. We need to provide this information to the user.

// migration is not needed for this workspace
continue;
}
LOG.info(
Copy link
Member

Choose a reason for hiding this comment

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

I'd change info level here to debug and add LOG.info with a message that migration stated before the loop.

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

Map<String, String> result = new HashMap<>();

for (WorkspaceImpl workspace :
iterate(
Copy link
Member

Choose a reason for hiding this comment

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

Iterate will eager fetch all objects from a database. I'd be nice to check how many memory it will consume when a number of workspaces is like 50 000 or the same as we have on codenvy.io.
If quite a lot then we should fetch workspace ids and names only. Something like that we've already done for another migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's unnecessary, I don't think there will ever happen a migration of significant size of workspaces, ever.

@@ -292,6 +292,11 @@ che.infra.docker.bootstrapper.installer_timeout_sec=180
# Once servers for one installer available - checks stopped.
che.infra.docker.bootstrapper.server_check_period_sec=3

# Enable to perform migration of workpace projects at Che startup.
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be only for che.infra.docker ? (prefix)

Choose a reason for hiding this comment

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

Unfortunately, I was not able to protect such a naming when Tyler did choose another naming technique. I don't remember that anyone was supporting me at that point. Does it seem better now?

@@ -246,6 +244,7 @@ init() {
export CHE_DOCKER_IP_EXTERNAL=${HOSTNAME}
fi
### Necessary to allow the container to write projects to the folder
export CHE_WORKSPACE_STORAGE__MASTER__PATH=/data/workspaces
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to duplicate the property CHE_WORKSPACE_STORAGE ?
so we have
CHE_WORKSPACE_STORAGE__MASTER__PATH=/data/workspaces
and
CHE_WORKSPACE_STORAGE="${CHE_DATA_HOST}/workspaces"

also /data should be replaced by ${CHE_DATA} property

Choose a reason for hiding this comment

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

Because these are different paths?

@skabashnyuk
Copy link
Contributor

Please change target branch of this pr to master branch.

@mkuznyetsov mkuznyetsov changed the base branch from che6 to master December 21, 2017 07:57
workspaceStoredByNameLocation,
workspaceStoredByIdLocation,
StandardCopyOption.ATOMIC_MOVE);
LOG.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

no, stay with info. We need to provide this information to the user.

entry.getKey(),
entry.getValue());
} catch (IOException e) {
LOG.debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

LOG.error

),
@NamedQuery(
name = "Workspace.getByTemporaryCount",
query = "SELECT COUNT(w) " + "FROM Workspace w " + "WHERE w.isTemporary = :temporary "
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure we have separate index on isTemporary field

Copy link
Contributor

Choose a reason for hiding this comment

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

index_workspace_istemporary exists. Nevermind

private static final Logger LOG = LoggerFactory.getLogger(LocalProjectsMigrator.class);

public void performMigration(String workspaceProjectsRootFolder) {
LOG.debug("Starting migration of workspace project files");
Copy link
Member

@sleshchenko sleshchenko Dec 22, 2017

Choose a reason for hiding this comment

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

let's change it to info

@mkuznyetsov mkuznyetsov changed the title Migrate workspace projects storage for Docker infrastructure Change worskpace project files storage path Dec 22, 2017
@mkuznyetsov mkuznyetsov merged commit 93b974d into master Dec 22, 2017
@mkuznyetsov mkuznyetsov deleted the che-3574 branch December 22, 2017 13:55
@benoitf benoitf added this to the 6.0.0-M4 milestone Dec 22, 2017
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Dec 22, 2017
@sunix
Copy link
Contributor

sunix commented Jan 2, 2018

Could we have a documentation on how to migrate ?

Add migration, that would move workspace projects to their new location. Occurs on Che startup.
Added configuration property to enable/disable this migration.

@slemeur
Copy link
Contributor

slemeur commented Jan 2, 2018

So now when a user wants to explore content of a workspace - he has to know the workspace id ?

@sunix
Copy link
Contributor

sunix commented Jan 2, 2018

@slemeur no it's just the inderlying host folder name

@sunix
Copy link
Contributor

sunix commented Jan 2, 2018

it needs a release note for users who have existing workspaces, notify them that migration is needed.

@skabashnyuk
Copy link
Contributor

@sunix

Could we have a documentation on how to migrate ?
it needs a release note for users who have existing workspaces, notify them that migration is >needed.

In this case, no action needed from the user, everything is going to happen automatically.

@slemeur

So now when a user wants to explore content of a workspace - he has to know the workspace id

Yes and no. If use specifies host.projects.root this folder will be mounted to each workspace he doesn't need to know anything about workspace id. But if data folder is configured by default we will put files in a tree where workspace id is used. That is important especially for multi-user use case when workspace names can be same for different users. And many users complain that this folder was overlapped in Che5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Outline of a bug - must adhere to the bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project becomes invalid after rename workspace
8 participants