コード例 #1
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @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);
      }
    }
  }
コード例 #2
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @Test
  public void testCreateDirWithEmptyPathComponents() throws Exception {
    VOLUME_NAME = "testCreateDirWithEmptyPathComponents";
    // Both directories should be created under "/"
    final String DIR1 = "/test";
    final String DIR2 = "/test//";
    final String DIR3 = "/test//testdir";

    // 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, DIR3, 0755);
    } catch (IOException ioe) {
      fail("failed to create testdirs");
    }

    try {
      volume.createDirectory(userCredentials, DIR2, 0755);
      fail("existing directory could be created");
    } catch (IOException ioe) {
    }

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

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

    entrySet = volume.readDir(userCredentials, DIR3, 0, 1000, false);
    assertEquals(2, entrySet.getEntriesCount());

    volume.removeDirectory(userCredentials, DIR3);
    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(2, entrySet.getEntriesCount());
  }
コード例 #3
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @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());
    }
  }
コード例 #4
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @BeforeClass
  public static void initializeTest() throws Exception {
    FSUtils.delTree(new java.io.File(SetupUtils.TEST_DIR));

    Logging.start(SetupUtils.DEBUG_LEVEL, SetupUtils.DEBUG_CATEGORIES);

    dirConfig = SetupUtils.createDIRConfig();
    dir = new DIRRequestDispatcher(dirConfig, SetupUtils.createDIRdbsConfig());
    dir.startup();
    dir.waitForStartup();

    testEnv =
        new TestEnvironment(
            new TestEnvironment.Services[] {
              TestEnvironment.Services.DIR_CLIENT,
              TestEnvironment.Services.TIME_SYNC,
              TestEnvironment.Services.RPC_CLIENT,
              TestEnvironment.Services.MRC
            });
    testEnv.start();

    userCredentials = UserCredentials.newBuilder().setUsername("test").addGroups("test").build();

    dirAddress = testEnv.getDIRAddress().getHostName() + ":" + testEnv.getDIRAddress().getPort();
    mrcAddress = testEnv.getMRCAddress().getHostName() + ":" + testEnv.getMRCAddress().getPort();

    defaultCoordinates =
        VivaldiCoordinates.newBuilder()
            .setXCoordinate(0)
            .setYCoordinate(0)
            .setLocalError(0)
            .build();
    defaultStripingPolicy =
        StripingPolicy.newBuilder()
            .setType(StripingPolicyType.STRIPING_POLICY_RAID0)
            .setStripeSize(128)
            .setWidth(1)
            .build();

    osds = new OSD[4];
    configs = SetupUtils.createMultipleOSDConfigs(4);

    // start three OSDs
    osds[0] = new OSD(configs[0]);
    osds[1] = new OSD(configs[1]);
    osds[2] = new OSD(configs[2]);
    osds[3] = new OSD(configs[3]);

    mrcClient = new MRCServiceClient(testEnv.getRpcClient(), null);

    options = new Options();
    client = ClientFactory.createClient(dirAddress, userCredentials, null, options);
    client.start();
  }
コード例 #5
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @Test
  public void testHardLink() throws Exception {
    VOLUME_NAME = "testHardLink";
    final String ORIG_FILE = "test.txt";
    final String LINKED_FILE = "test-link.txt";
    final String LINKED_FILE2 = "test-link2.txt";

    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>());

    // create file
    openResponse open = null;
    RPCResponse<openResponse> resp = null;
    try {
      resp =
          mrcClient.open(
              testEnv.getMRCAddress(),
              auth,
              userCredentials,
              VOLUME_NAME,
              ORIG_FILE,
              FileAccessManager.O_CREAT,
              0,
              0777,
              defaultCoordinates);
      open = resp.get();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(open);

    // create link
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    volume.link(userCredentials, ORIG_FILE, LINKED_FILE);

    open = null;
    resp = null;
    try {
      resp =
          mrcClient.open(
              testEnv.getMRCAddress(),
              auth,
              userCredentials,
              VOLUME_NAME,
              "test-hardlink.txt",
              FileAccessManager.O_CREAT,
              0,
              0,
              defaultCoordinates);
      open = resp.get();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(open);

    // check whether both filenames refer to the same file
    Stat stat1 = null;
    Stat stat2 = null;
    RPCResponse<getattrResponse> resp1 = null;
    RPCResponse<getattrResponse> resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE, 0);
      stat2 = resp2.get().getStbuf();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(stat1);
    assertNotNull(stat2);

    assertEquals(stat1.getIno(), stat1.getIno());
    assertEquals(2, stat1.getNlink());

    // create another link to the second file
    volume.link(userCredentials, LINKED_FILE, LINKED_FILE2);

    // check whether both links refer to the same file
    stat1 = null;
    stat2 = null;
    resp1 = null;
    resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0);
      stat2 = resp2.get().getStbuf();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp2.freeBuffers();
      }
    }
    assertEquals(stat1.getIno(), stat2.getIno());
    assertEquals(3, stat1.getNlink());

    // delete one of the links
    volume.unlink(userCredentials, LINKED_FILE);

    // check whether remaining links refer to the same file
    stat1 = null;
    stat2 = null;
    resp1 = null;
    resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0);
      stat2 = resp2.get().getStbuf();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp2.freeBuffers();
      }
    }
    assertEquals(stat1.getIno(), stat2.getIno());
    assertEquals(2, stat1.getNlink());

    // delete the other two links
    volume.unlink(userCredentials, ORIG_FILE);
    volume.unlink(userCredentials, LINKED_FILE2);

    try {
      mrcClient
          .getattr(testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0)
          .get();
      fail("file should not exist anymore");
    } catch (Exception exc) {
    }

    try {
      mrcClient
          .getattr(testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0)
          .get();
      fail("file should not exist anymore");
    } catch (Exception exc) {
    }

    //
    // // create two links to a directory
    // invokeSync(client.mkdir(mrcAddress, RPCAuthentication.authNone, uc,
    // volumeName, "testDir1", 0));
    // try {
    // invokeSync(client.link(mrcAddress, RPCAuthentication.authNone, uc,
    // volumeName, "testDir1",
    // "testDir1/testDir2"));
    // fail("links to directories should not be allowed");
    // } catch (Exception exc) {
    // }
    // }
    //
  }
コード例 #6
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @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());
  }
コード例 #7
0
ファイル: VolumeTest.java プロジェクト: 2510/xtreemfs
  @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]);
  }