Search code examples
svnreplication

svn repository, update and commit from different remote locations


In our company we have a tricky environment where people work in several countries. For performance reasons (network access) we would like to replicate our SVN repositories using the following scheme.

Let's say we have French people and German people:

  • Our "master" SVN repository is located in France, people are allowed to commit into this repository
  • We have a "slave-replication" copy in Germany, people are not allowed to commit into this repository

In my application I would like to:

  1. Find the "closest" SVN repository based on the minimum ping
  2. Checkout/update from this closest SVN repository
  3. If the user wants to commit things, commit to the French "master" server

Is there any way to do it using SVN ? Any other ideas ? It's not possible to switch to GIT or another version control system. Thanks!


Solution

  • Here is how I achieved to do it in the end:

    1. SVN replication: simply use the svnsync command to propagate any commit from master to slave repositories
    2. SVN relocation: use the svn relocate command to do it before and after each operation that would do something in the remote (commit, create branch, share, ...)

    In the application:

    1. Find the closest server based on ping. As I'm writing Java code, I did write my own way to find the ping value
    public static Duration ping(String host) {
        Instant startTime = Instant.now();
        try {
            InetAddress address = InetAddress.getByName(host);
            if (address.isReachable(1000)) {
                return Duration.between(startTime, Instant.now());
            }
        } catch (IOException e) {
            // host not available, nothing to do here
        }
        return Duration.ofDays(1);
    }
    
    1. When doing an operation that will modify the remote repository, check if the local SVN copy is a master or slave URL, if it's not a master URL do a svn relocate before the operation, and another svn relocate after the operation to get back the the faster SVN clone repository.