Ejemplo n.º 1
0
 @Test
 public void testGetXattrSize() throws Exception {
   VOLUME_NAME = "testGetXattrSize";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_SYNC.getNumber(),
           0777);
   fh.close();
   int size = volume.getXAttrSize(userCredentials, fileName, "xtreemfs.set_repl_update_policy");
   assertEquals(0, size);
   size = volume.getXAttrSize(userCredentials, fileName, "xtreemfs.owner");
   assertEquals(userCredentials.getUsername().length(), size);
   size = volume.getXAttrSize(userCredentials, fileName, "doesnt-exist");
   assertEquals(-1, size);
   volume.setXAttr(userCredentials, fileName, "foo", "bar", XATTR_FLAGS.XATTR_FLAGS_CREATE);
   size = volume.getXAttrSize(userCredentials, fileName, "foo");
   assertEquals(3, size);
   size = volume.getXAttrSize(userCredentials, fileName, "doesnt-exist-in-cache");
   assertEquals(-1, size);
 }
Ejemplo n.º 2
0
  @Test
  public void testReplicaAddListRemove() throws Exception {
    VOLUME_NAME = "testReplicaAddListRemove";
    final String fileName = "testfile";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // set replication update policy of the file
    int flags = ReplicationFlags.setSequentialStrategy(0);
    flags = ReplicationFlags.setFullReplica(flags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE, 2, flags);
    FileHandle fileHandle =
        volume.openFile(
            userCredentials, fileName, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(), 0777);
    fileHandle.close();

    assertEquals(2, volume.listReplicas(userCredentials, fileName).getReplicasCount());

    String osdUUID = volume.getSuitableOSDs(userCredentials, fileName, 1).get(0);
    Replica replica =
        Replica.newBuilder()
            .addOsdUuids(osdUUID)
            .setStripingPolicy(defaultStripingPolicy)
            .setReplicationFlags(flags)
            .build();
    volume.addReplica(userCredentials, fileName, replica);
    assertEquals(3, volume.listReplicas(userCredentials, fileName).getReplicasCount());

    volume.removeReplica(userCredentials, fileName, replica.getOsdUuids(0));
    assertEquals(2, volume.listReplicas(userCredentials, fileName).getReplicasCount());
  }
Ejemplo n.º 3
0
  @Test
  public void testRenameFile() throws Exception {
    VOLUME_NAME = "testRenameFile";
    String fileName = "testfile";
    String renamedFileName = "renamed";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    FileHandle fh =
        volume.openFile(
            userCredentials,
            fileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);
    fh.close();
    // nothing should happen
    volume.rename(userCredentials, fileName, fileName);
    DirectoryEntries dir = volume.readDir(userCredentials, "/", 0, 100, true);
    assertEquals(fileName, dir.getEntries(2).getName());
    assertEquals(3, dir.getEntriesCount());

    volume.rename(userCredentials, fileName, renamedFileName);
    dir = volume.readDir(userCredentials, "/", 0, 100, true);
    assertEquals(renamedFileName, dir.getEntries(2).getName());
    assertEquals(3, dir.getEntriesCount());
  }
Ejemplo n.º 4
0
  @Test
  public void testSetGetListXattr() throws Exception {
    VOLUME_NAME = "testSetGetListXattr";
    final String TESTFILE = "testfile";

    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    FileHandle fh =
        volume.openFile(
            userCredentials, TESTFILE, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
    fh.close();

    int initialNumberOfXattr = volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount();

    // This xattr should not exist
    String xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertNull(xattr);

    // and therefore should have no size
    assertEquals(-1, volume.getXAttrSize(userCredentials, TESTFILE, "foobarasdf"));

    // creating a new Xattr should increase the number of xattrs
    volume.setXAttr(
        userCredentials, TESTFILE, "foobarasdf", "nyancat", XATTR_FLAGS.XATTR_FLAGS_CREATE);

    assertEquals(
        initialNumberOfXattr + 1, volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount());

    xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertEquals("nyancat", xattr);

    // delete the created Xattr
    volume.removeXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertEquals(
        initialNumberOfXattr, volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount());
    xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertNull(xattr);

    // same with xtreemfs. attributes.
    try {
      xattr = volume.getXAttr(userCredentials, TESTFILE, "xtreemfs.nyancat");
      fail("nyancat is not a valid system attribute");
    } catch (Exception e) {
    }

    xattr =
        volume.getXAttr(
            userCredentials, TESTFILE, "xtreemfs." + SysAttrs.set_repl_update_policy.toString());
    assertEquals(ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE, xattr);

    // read existing systemflag
    xattr =
        volume.getXAttr(userCredentials, TESTFILE, "xtreemfs." + SysAttrs.object_type.toString());
    assertEquals("1", xattr);
  }
Ejemplo n.º 5
0
  @Test
  public void testVolumeQuota() throws Exception {
    final String VOLUME_NAME = "testVolumeQuota";

    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    volume.setXAttr(userCredentials, "/", "xtreemfs.quota", "8", XATTR_FLAGS.XATTR_FLAGS_CREATE);

    assertEquals("8", volume.getXAttr(userCredentials, "/", "xtreemfs.quota"));

    int flags =
        SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
            | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber();

    byte[] content = "foo foo foo".getBytes(); // 11 bytes will exceed quota

    FileHandle file = volume.openFile(userCredentials, "/test1.txt", flags, 0777);

    boolean osdWriteException = false;
    try {
      file.write(userCredentials, content, content.length, 0);
    } catch (Exception ex) {
      osdWriteException = true;
    }

    if (!osdWriteException) {
      fail("OSD performed write operation although it exceeds the quota.");
    }

    content = "foo bar ".getBytes(); // 8 bytes to fit quota perfectly
    file.write(userCredentials, content, content.length, 0);
    file.close();

    try {
      file = volume.openFile(userCredentials, "/test2.txt", flags, 0777);
      assertTrue(false);
    } catch (PosixErrorException exc) {
      // check if right exception was thrown
      if (!exc.getMessage().contains("POSIX_ERROR_ENOSPC")) {
        assertTrue(false);
      }
    }
  }
Ejemplo n.º 6
0
  /** Test log file creation. */
  public void testFileCreation() throws IOException, DatabaseException {

    FileManagerTestUtils.createLogFile(fileManager, envImpl, FILE_SIZE);
    FileManagerTestUtils.createLogFile(fileManager, envImpl, FILE_SIZE);

    String[] jeFiles = fileManager.listFiles(FileManager.JE_SUFFIXES);

    assertEquals("Should have two files", 2, jeFiles.length);

    /* Make a fake files with confusing names. */
    File fakeFile1 = new File(envHome, "00000abx.jdb");
    File fakeFile2 = new File(envHome, "10.10.jdb");
    fakeFile1.createNewFile();
    fakeFile2.createNewFile();

    jeFiles = fileManager.listFiles(FileManager.JE_SUFFIXES);
    assertEquals("Should have two files", 2, jeFiles.length);

    /* Open the two existing log files. */
    FileHandle file0Handle = fileManager.getFileHandle(0L);
    FileHandle file1Handle = fileManager.getFileHandle(1L);

    jeFiles = fileManager.listFiles(FileManager.JE_SUFFIXES);
    assertEquals("Should have two files", 2, jeFiles.length);
    file0Handle.release();
    file1Handle.release();

    /* Empty the cache and get them again. */
    fileManager.clear();
    file0Handle = fileManager.getFileHandle(0L);
    file1Handle = fileManager.getFileHandle(1L);

    jeFiles = fileManager.listFiles(FileManager.JE_SUFFIXES);
    assertEquals("Should have two files", 2, jeFiles.length);
    file0Handle.close();
    file1Handle.close();
    file0Handle.release();
    file1Handle.release();

    fakeFile1.delete();
    fakeFile2.delete();
  }
Ejemplo n.º 7
0
 @Test(expected = PosixErrorException.class)
 public void testReadLinkWithoutLink() throws Exception {
   VOLUME_NAME = "testReadLinkWithoutLink";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials, fileName, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
   fh.close();
   volume.readLink(userCredentials, fileName);
 }
Ejemplo n.º 8
0
  @Test
  public void testTruncate() throws Exception {
    VOLUME_NAME = "testTruncate";
    String fileName = "testfile";
    String emptyFileName = "emptyFileName";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    FileHandle fileHandle =
        volume.openFile(
            userCredentials,
            fileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);

    String data = "1234567890";
    fileHandle.write(userCredentials, data.getBytes(), data.length(), 0);
    fileHandle.flush();

    assertEquals(data.length(), volume.getAttr(userCredentials, fileName).getSize());

    volume.truncate(userCredentials, fileName, 5);
    assertEquals(5, volume.getAttr(userCredentials, fileName).getSize());
    fileHandle.close();

    fileHandle =
        volume.openFile(
            userCredentials,
            emptyFileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);
    assertEquals(0, fileHandle.getAttr(userCredentials).getSize());
    volume.truncate(userCredentials, emptyFileName, 1000);
    assertEquals(1000, fileHandle.getAttr(userCredentials).getSize());
    fileHandle.close();
  }
Ejemplo n.º 9
0
 @Test
 public void testAccessSuccess() throws Exception {
   VOLUME_NAME = "testAccessSuccess";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
           0753);
   fh.close();
   volume.access(userCredentials, fileName, 0753);
 }
Ejemplo n.º 10
0
  @Test
  public void testReadDirMultipleChunks() throws Exception {
    options.setReaddirChunkSize(2);

    VOLUME_NAME = "testReadDirMultipleChunks";
    final String TESTFILE = "test";
    final int fileCount = 10;

    // create volume
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // create some files
    for (int i = 0; i < fileCount; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // test 'readDir' across multiple readDir chunks.
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "/", 0, 1000, false);
    assertEquals(2 + fileCount, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    for (int i = 0; i < fileCount; i++) {
      assertEquals(TESTFILE + i, entrySet.getEntries(2 + i).getName());
    }
  }
Ejemplo n.º 11
0
 @Test
 public void testReadLinkWithLink() throws Exception {
   VOLUME_NAME = "testReadLinkWithLink";
   String fileName = "testfile";
   String linkName = "linkToFile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
           0777);
   fh.close();
   volume.symlink(userCredentials, fileName, linkName);
   assertEquals(fileName, volume.readLink(userCredentials, linkName));
 }
Ejemplo n.º 12
0
  /**
   * Test if files inherit the group from its parent if the setgid bit is set, and if subdirectories
   * inherit the group and the setgid bit.
   */
  @Test
  public void testSetgid() throws Exception {
    VOLUME_NAME = "testSetgid";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    volume.createDirectory(userCredentials, "/DIR1", 0777);

    Stat stat;
    stat = volume.getAttr(userCredentials, "/DIR1");

    int mode = stat.getMode() | 02000;
    stat = stat.toBuilder().setGroupId("foobar").setMode(mode).build();

    UserCredentials rootCreds =
        userCredentials.toBuilder().setUsername("root").setGroups(0, "root").build();
    volume.setAttr(
        rootCreds,
        "/DIR1",
        stat,
        Setattrs.SETATTR_MODE.getNumber() | Setattrs.SETATTR_GID.getNumber());

    // Test if the setgid bit and the group is set
    stat = volume.getAttr(userCredentials, "/DIR1");
    assertEquals(02000, stat.getMode() & 02000);
    assertEquals("foobar", stat.getGroupId());

    // Test if new subdirectories inherit the setgid bit and the group
    volume.createDirectory(userCredentials, "/DIR1/DIR2", 0777);
    stat = volume.getAttr(userCredentials, "/DIR1/DIR2");
    assertEquals(02000, stat.getMode() & 02000);
    assertEquals("foobar", stat.getGroupId());

    // Test if new files inherit the group
    FileHandle fh =
        volume.openFile(
            userCredentials, "/DIR1/FILE1", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
    fh.close();
    stat = volume.getAttr(userCredentials, "/DIR1/FILE1");
    assertEquals("foobar", stat.getGroupId());

    volume.close();
  }
Ejemplo n.º 13
0
  @Test
  public void testGetSetAttr() throws Exception {
    VOLUME_NAME = "testGetSetAttr";

    final String TESTFILE = "testfile";
    final String TESTDIR = "testdir";

    final int TESTMODE = 0731;

    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    volume.createDirectory(userCredentials, TESTDIR, TESTMODE);
    FileHandle fh =
        volume.openFile(
            userCredentials,
            TESTDIR + "/" + TESTFILE,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(),
            TESTMODE);
    fh.close();

    Stat stat = volume.getAttr(userCredentials, TESTDIR);
    assertEquals(userCredentials.getUsername(), stat.getUserId());
    assertEquals(userCredentials.getGroups(0), stat.getGroupId());
    assertEquals(0, stat.getSize());
    assertTrue(stat.getAtimeNs() > 0);
    assertTrue(stat.getCtimeNs() > 0);
    assertTrue(stat.getMtimeNs() > 0);
    assertTrue((stat.getMode() & TESTMODE) > 0);
    assertEquals(1, stat.getNlink());

    stat = volume.getAttr(userCredentials, TESTDIR + "/" + TESTFILE);
    assertEquals(userCredentials.getUsername(), stat.getUserId());
    assertEquals(userCredentials.getGroups(0), stat.getGroupId());
    assertEquals(0, stat.getSize());
    assertTrue(stat.getAtimeNs() > 0);
    assertTrue(stat.getCtimeNs() > 0);
    assertTrue(stat.getMtimeNs() > 0);
    assertTrue((stat.getMode() & TESTMODE) == TESTMODE);
    assertEquals(1, stat.getNlink());

    stat = stat.toBuilder().setGroupId("foobar").setUserId("FredFoobar").build();
    try {
      volume.setAttr(
          userCredentials,
          TESTDIR,
          stat,
          Setattrs.SETATTR_UID.getNumber() | Setattrs.SETATTR_GID.getNumber());
      fail("changing username and groups should be restricted to superuser");
    } catch (PosixErrorException e) {
    }

    UserCredentials rootCreds =
        userCredentials.toBuilder().setUsername("root").setGroups(0, "root").build();

    volume.setAttr(
        rootCreds,
        TESTDIR,
        stat,
        Setattrs.SETATTR_UID.getNumber() | Setattrs.SETATTR_GID.getNumber());

    stat = volume.getAttr(userCredentials, TESTDIR);
    assertEquals("FredFoobar", stat.getUserId());
    assertEquals("foobar", stat.getGroupId());
    assertTrue((stat.getMode() & TESTMODE) > 0);

    stat = stat.toBuilder().setMode(0777).build();
    volume.setAttr(
        userCredentials, TESTDIR + "/" + TESTFILE, stat, Setattrs.SETATTR_MODE.getNumber());
    stat = volume.getAttr(userCredentials, TESTDIR + "/" + TESTFILE);
    assertTrue((stat.getMode() & 0777) == 0777);
  }
Ejemplo n.º 14
0
  @Test
  public void testCreateDelete() throws Exception {
    VOLUME_NAME = "testCreateDelete";
    // Both directories should be created under "/"
    final String DIR1 = "/testdir1";
    final String DIR2 = "testdir2";

    final String TESTFILE = "testfile";
    // create volume
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // create some files and directories
    try {
      volume.createDirectory(userCredentials, DIR1, 0755);
      volume.createDirectory(userCredentials, DIR2, 0755);
    } catch (IOException ioe) {
      fail("failed to create testdirs");
    }

    for (int i = 0; i < 10; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              DIR1 + "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // // try to create a file w/o a name
    try {
      volume.openFile(userCredentials, "", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("missing filename");
    } catch (Exception e) {
    }

    // try to create an already existing file
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_EXCL.getNumber()
              | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file already exists");
    } catch (Exception e) {
    }

    // file in file creation should fail
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1/foo.txt",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file in file creation");
    } catch (Exception e) {
    }

    // should fail
    try {
      volume.createDirectory(userCredentials, "/", 0);
      fail("directory already exists");
    } catch (PosixErrorException exc) {
    }

    // test 'readDir' and 'stat'
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(4, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    assertEquals(DIR1, "/" + entrySet.getEntries(2).getName());
    assertEquals("/" + DIR2, "/" + entrySet.getEntries(3).getName());

    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(12, entrySet.getEntriesCount());

    // test 'delete'
    volume.unlink(userCredentials, DIR1 + "/" + TESTFILE + "4");
    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(11, entrySet.getEntriesCount());

    volume.removeDirectory(userCredentials, DIR2);
    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(3, entrySet.getEntriesCount());
  }
Ejemplo n.º 15
0
  @Test
  public void testGetStripeLocationsWithMultipleStripes() throws Exception {
    VOLUME_NAME = "testGetStripeLocatationsWithMultipleStripes";
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0777,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_POSIX,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        2,
        1,
        new ArrayList<GlobalTypes.KeyValuePair>());
    Volume volume = client.openVolume(VOLUME_NAME, options.generateSSLOptions(), options);

    // set replication update policy of the file
    int replicationFlags = ReplicationFlags.setSequentialStrategy(0);
    replicationFlags = ReplicationFlags.setFullReplica(replicationFlags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY, 2, replicationFlags);

    // create new striping policy with width 2
    StripingPolicy stripingPolicy =
        StripingPolicy.newBuilder()
            .setStripeSize(2)
            .setWidth(2)
            .setType(StripingPolicyType.STRIPING_POLICY_RAID0)
            .build();

    // create file
    final String FILENAME = "/foobar.tzt";
    int flags = SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber();
    FileHandle fileHandle = volume.openFile(userCredentials, FILENAME, flags, 0777);

    // write more than 2kb to the byte to ensure the second stripe is used
    byte[] data = new byte[3000];
    for (int i = 0; i < data.length; i++) {
      data[i] = 'F';
    }
    fileHandle.write(userCredentials, data, data.length, 0);
    fileHandle.close();

    // create replica and add it
    List<String> suitableOsds = volume.getSuitableOSDs(userCredentials, FILENAME, 2);
    Replica replica =
        Replica.newBuilder()
            .setReplicationFlags(replicationFlags)
            .setStripingPolicy(stripingPolicy)
            .addAllOsdUuids(suitableOsds)
            .build();
    volume.addReplica(userCredentials, FILENAME, replica);

    List<StripeLocation> stripeLocations =
        volume.getStripeLocations(userCredentials, FILENAME, 0, 4000);
    assertEquals(2, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);

    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(2048, stripeLocations.get(0).getLength());
    assertEquals(2048, stripeLocations.get(1).getStartSize());
    assertEquals(4000 - 2048, stripeLocations.get(1).getLength());

    assertEquals(stripeLocations.get(0).getUuids()[0], stripeLocations.get(1).getUuids()[0]);
    assertEquals(stripeLocations.get(0).getUuids()[1], stripeLocations.get(1).getUuids()[1]);
    assertNotSame(stripeLocations.get(0).getUuids()[2], stripeLocations.get(1).getUuids()[2]);
  }
Ejemplo n.º 16
0
  @Test
  public void testGetStripeLocations() throws Exception {
    VOLUME_NAME = "testGetStripeLocatations";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // set replication update policy of the file
    int flags = ReplicationFlags.setSequentialStrategy(0);
    flags = ReplicationFlags.setFullReplica(flags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY, 2, flags);

    final String FILENAME = "/foobar.tzt";
    FileHandle fileHandle =
        volume.openFile(
            userCredentials, FILENAME, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(), 0777);
    byte[] data = new byte[6];
    for (int i = 0; i < data.length; i++) {
      data[i] = (byte) "FOOBAR".charAt(i);
    }
    fileHandle.write(userCredentials, data, data.length, 0);
    fileHandle.close();
    List<StripeLocation> stripeLocations =
        volume.getStripeLocations(userCredentials, FILENAME, 0, 100);
    assertEquals(1, stripeLocations.size());
    assertEquals(2, stripeLocations.get(0).getUuids().length);
    assertEquals(2, stripeLocations.get(0).getHostnames().length);
    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(100, stripeLocations.get(0).getLength());

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 200, 123);
    assertEquals(1, stripeLocations.size());
    assertEquals(2, stripeLocations.get(0).getUuids().length);
    assertEquals(2, stripeLocations.get(0).getHostnames().length);
    assertEquals(200, stripeLocations.get(0).getStartSize());
    assertEquals(123, stripeLocations.get(0).getLength());

    List<String> suitableOsds = volume.getSuitableOSDs(userCredentials, FILENAME, 1);
    Replica replica =
        Replica.newBuilder()
            .setStripingPolicy(defaultStripingPolicy)
            .setReplicationFlags(flags)
            .addOsdUuids(suitableOsds.get(0))
            .build();
    volume.addReplica(userCredentials, FILENAME, replica);

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 0, 100);
    assertEquals(1, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);
    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(100, stripeLocations.get(0).getLength());

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 200, 123);
    assertEquals(1, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);
    assertEquals(200, stripeLocations.get(0).getStartSize());
    assertEquals(123, stripeLocations.get(0).getLength());

    volume.close();
  }