@Override
 public void startVolume(final Volume volume, final BufferedWriter out) throws IOException {
   out.write("\t\t<volume");
   out.write(" h=\"" + volume.getHourOfDayStartingWithOne() + "\"");
   out.write(" val=\"" + volume.getValue() + "\"");
   out.write(" />\n");
 }
Example #2
1
  protected long[] getLinkedRecordsIndexVals(long indexVal) {
    long[] linkedRecords = null;

    int linkedPos = 0;
    if ((indexVal & MASK_LINKED) != 0) {
      // record is composed of multiple linked records, so collect all of them
      linkedRecords = new long[2];

      // traverse linked records
      long linkedVal = phys.getLong(indexVal & MASK_OFFSET);
      for (; ; ) {
        if (linkedPos == linkedRecords.length) // grow if necessary
        linkedRecords = Arrays.copyOf(linkedRecords, linkedRecords.length * 2);
        // store last linkedVal
        linkedRecords[linkedPos] = linkedVal;

        if ((linkedVal & MASK_LINKED) == 0) {
          break; // this is last linked record, so break
        }
        // move and read to next
        linkedPos++;
        linkedVal = phys.getLong(linkedVal & MASK_OFFSET);
      }
    }
    return linkedRecords;
  }
Example #3
0
  protected void put2(DataIO.DataOutputByteArray out, long ioRecid, long[] indexVals) {
    assert (disableLocks || locks[Store.lockPos(ioRecid)].writeLock().isHeldByCurrentThread());
    index.putLong(ioRecid, indexVals[0] | MASK_ARCHIVE);
    // write stuff
    if (indexVals.length == 1 || indexVals[1] == 0) { // is more then one? ie linked
      // write single

      phys.putData(indexVals[0] & MASK_OFFSET, out.buf, 0, out.pos);

    } else {
      int outPos = 0;
      // write linked
      for (int i = 0; i < indexVals.length; i++) {
        final int c = i == indexVals.length - 1 ? 0 : 8;
        final long indexVal = indexVals[i];
        final boolean isLast = (indexVal & MASK_LINKED) == 0;
        assert (isLast == (i == indexVals.length - 1));
        final int size = (int) (indexVal >>> 48);
        final long offset = indexVal & MASK_OFFSET;

        // write data
        phys.putData(offset + c, out.buf, outPos, size - c);
        outPos += size - c;

        if (c > 0) {
          // write position of next linked record
          phys.putLong(offset, indexVals[i + 1]);
        }
      }
      if (outPos != out.pos) throw new AssertionError();
    }
  }
Example #4
0
 protected void initCreate() {
   highestRecid.set(RECID_LAST_RESERVED);
   // TODO header  here
   long feat = makeFeaturesBitmap();
   vol.putLong(HEAD_FEATURES, feat);
   vol.sync();
 }
Example #5
0
  public static void main(String[] args) {

    /**/
    // UNCOMMENT THIS WHEN YOU DO AREA
    Area[] twos = new Area[5];
    for (int i = 0; i < twos.length; i++) {
      twos[i] = makeRandomAreaShape();
    }
    System.out.println("Area tests:");
    for (Area a : twos) {
      System.out.println(a);
      System.out.println(a.getArea());
    }

    /**/
    // UNCOMMENT THIS WHEN YOU DO VOLUME
    Volume[] threes = new Volume[6];
    for (int i = 0; i < threes.length; i++) {
      threes[i] = makeRandomVolumeShape();
    }
    System.out.println("\nVolume tests:");
    for (Volume v : threes) {
      System.out.println(v);
      System.out.println(v.getVolume());
    }
  }
Example #6
0
  private void insertOrUpdate(long recid, DataIO.DataOutputByteArray out, boolean isInsert) {
    if (CC.ASSERT) assertWriteLocked(lockPos(recid));

    // TODO assert indexTable state, record should already exist/not exist

    final int realSize = out == null ? 0 : out.pos;
    final int shiftedSize = out == null ? 0 : realSize + 1; // one additional state to indicate null
    final int headSize =
        1
            + // instruction
            DataIO.packLongSize(longParitySet(recid))
            + // recid
            DataIO.packLongSize(longParitySet(shiftedSize)); // length

    long offset = alloc(headSize, headSize + realSize);
    final long origOffset = offset;
    // ensure available worst case scenario
    vol.ensureAvailable(offset + headSize + realSize);
    // instruction
    vol.putUnsignedByte(offset, isInsert ? I_INSERT : I_UPDATE);
    offset++;
    // recid
    offset += vol.putPackedLong(offset, longParitySet(recid));
    // size
    offset += vol.putPackedLong(offset, longParitySet(shiftedSize));

    if (realSize != 0) vol.putDataOverlap(offset, out.buf, 0, out.pos);

    // -3 is null record
    // -2 is zero size record
    indexTablePut(recid, out == null ? -3 : (realSize == 0) ? -2 : origOffset);
  }
Example #7
0
  @Test
  public void testCreateDirectoryRecursive() throws Exception {
    VOLUME_NAME = "testCreateDirectoryRecursive";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    final String directory1 = "/home/foo/bar/user/xtreemfs/test/bar/foo";
    final String directroy2 = "/home/foo/path/with/slash/at/end/";
    volume.createDirectory(userCredentials, directory1, 0777, true);
    volume.createDirectory(userCredentials, directroy2, 0777, true);

    final String[] dirs1 = directory1.split("/");
    final String[] dirs2 = directroy2.split("/");

    String tempdir = "";
    for (int i = 1; i < dirs1.length; i++) {
      tempdir = tempdir + "/" + dirs1[i];
      assertTrue(isDirectory(volume, tempdir));
    }

    tempdir = "";
    for (int i = 1; i < dirs2.length; i++) {
      tempdir = tempdir + "/" + dirs2[i];
      assertTrue(isDirectory(volume, tempdir));
    }
    volume.close();
  }
Example #8
0
  /**
   * Returns an array containing a <code>TreeInfo</code> element for each <code>Tree</code> in the
   * specified volume. If there is no volume with the specified name or if Persistit is not
   * initialized then this method returns an empty array.
   *
   * @param volumeName The name (or unique partial name) of the volume for which information is
   *     being requested.
   * @return The array
   */
  @Override
  public TreeInfo[] getTreeInfoArray(final String volumeName) throws RemoteException {
    if (volumeName == null) {
      return new TreeInfo[0];
    }
    final Volume volume = _persistit.getVolume(volumeName);
    if (volume == null) return new TreeInfo[0];

    try {
      final String[] treeNames = volume.getTreeNames();
      TreeInfo[] results = new TreeInfo[treeNames.length + 1];
      int count = 0;
      results[count++] = new TreeInfo(volume.getDirectoryTree());
      for (int index = 0; index < treeNames.length; index++) {
        final TreeInfo info = volume.getTreeInfo(treeNames[index]);
        if (info != null) {
          results[count++] = info;
        }
      }
      if (count < results.length) {
        final TreeInfo[] temp = new TreeInfo[count];
        System.arraycopy(results, 0, temp, 0, count);
        results = temp;
      }
      return results;
    } catch (final PersistitException pe) {
      throw new WrappedRemoteException(pe);
    }
  }
Example #9
0
 /**
  * Return a <code>BufferInfo</code> reflecting the state of a page containing the specified key.
  * The <code>volumeName</code> and <code>treeName</code> parameters specify a {@link Tree} in
  * which to seach for the key. The <code>level</code> parameter indicates whether the data page,
  * or one of the pages on the index path to that data page should be returned. Level 0 refers to
  * the data path, level 1 is the lowest index level, and level d-1 where d is the number of levels
  * in the the tree represents the three's root page.
  *
  * <p>Specify <code>treeName</code> as <code>null</code> to access the volume's directory tree.
  *
  * @param volumeName the name of the volume
  * @param treeName the name of the tree within the volume, or <code>null</code> for the directory
  *     tree
  * @param key a <code>KeyState</code> representing a key
  * @param level tree level: 0 for root, 1...d-1 for index pages of a tree having depth d.
  * @return a <code>BufferInfo</code> object reflecting the selected page, or <code>null</code> if
  *     the specified tree does not exist.
  * @throws RemoteException
  */
 @Override
 public BufferInfo getBufferInfo(
     final String volumeName, final String treeName, final KeyState key, final int level)
     throws RemoteException {
   try {
     Exchange exchange;
     final Volume volume = _persistit.getVolume(volumeName);
     if (volume == null) {
       return null;
     }
     if (treeName == null) {
       exchange = volume.getStructure().directoryExchange();
     } else {
       exchange = _persistit.getExchange(volume, treeName, false);
     }
     key.copyTo(exchange.getKey());
     final Buffer buffer = exchange.fetchBufferCopy(level);
     final BufferInfo info = new BufferInfo();
     buffer.populateInfo(info);
     return info;
   } catch (final TreeNotFoundException tnfe) {
     return null;
   } catch (final PersistitException pe) {
     throw new WrappedRemoteException(pe);
   }
 }
  /**
   * Test for bug https://bugs.launchpad.net/akiban-persistit/+bug/1045983
   *
   * Truncating a dynamically created volume results in corrupted journal If
   * you dynamically load a volume, truncate it (without adding any trees),
   * and then close it, the next time the database is initialized a fatal
   * exception is thrown:
   *
   * <code><pre>
   *
   * [JOURNAL_COPIER] WARNING Missing volume truncated referenced at journal address 364
   * [main] WARNING Missing volume truncated referenced at journal address 17,004 (6 similar occurrences in 0 seconds)
   * Exception in thread "main" com.persistit.exception.InvalidPageAddressException: Page 1 out of bounds [0-1]
   *  at com.persistit.VolumeStorageV2.readPage(VolumeStorageV2.java:426)
   *  at com.persistit.Buffer.load(Buffer.java:456)
   *  at com.persistit.BufferPool.get(BufferPool.java:780)
   *  at com.persistit.Tree.setRootPageAddress(Tree.java:203)
   *  at com.persistit.VolumeStructure.init(VolumeStructure.java:70)
   *  at com.persistit.VolumeStorageV2.open(VolumeStorageV2.java:217)
   *  at com.persistit.Volume.open(Volume.java:442)
   *  at com.persistit.Persistit.loadVolume(Persistit.java:1066)
   *  at Truncate.main(Truncate.java:30)
   *
   * @throws Exception
   *
   *             </pre></code>
   *
   *             This test is currently disabled pending a fix.
   *
   */
  @Test
  @Ignore
  public void truncateDynamicVolumes() throws Exception {

    VolumeSpecification volumeSpec;
    _persistit.close();

    final Persistit db = new Persistit(_config);

    for (int i = 0; i < 2; i++) {
      try {
        volumeSpec =
            new VolumeSpecification(
                DATA_PATH + "/truncated", null, 16384, 1, 1000, 1, true, false, false);
        final Volume volume = db.loadVolume(volumeSpec);
        volume.truncate();
        // the following may be omitted, and the problem still exhibited
        final Exchange dbex = db.getExchange("truncated", "greetings", true);
        dbex.getKey().append("ave");
        dbex.getValue().put("mundus");
        dbex.store();
        dbex.getKey().to(Key.BEFORE);
        while (dbex.next()) {
          System.out.println(dbex.getKey().reset().decode() + " " + dbex.getValue().get());
        }
        db.releaseExchange(dbex);
        // the preceding may be omitted, and the problem still exhibited
      } finally {
        db.close();
      }
    }
  }
Example #11
0
  @Override
  public void close() {
    if (closed) return;
    commitLock.lock();
    try {
      if (closed) return;

      if (isSnapshot) {
        snapshots.remove(this);
        return;
      }

      vol.sync();
      vol.close();
      indexTable.close();

      if (caches != null) {
        for (Cache c : caches) {
          c.close();
        }
        Arrays.fill(caches, null);
      }
      closed = true;
    } finally {
      commitLock.unlock();
    }
  }
Example #12
0
 static void update() {
   final Multimap<String, String> partitionVolumeMap = HashMultimap.create();
   final EntityTransaction db = Entities.get(Volume.class);
   try {
     for (final Volume v : Entities.query(Volume.named(null, null))) {
       partitionVolumeMap.put(v.getPartition(), v.getDisplayName());
     }
     db.rollback();
   } catch (final Exception ex) {
     Logs.extreme().error(ex, ex);
     db.rollback();
   }
   Logs.extreme()
       .debug("Volume state update: " + Joiner.on("\n").join(partitionVolumeMap.entries()));
   for (final String partition : partitionVolumeMap.keySet()) {
     try {
       final Map<String, StorageVolume> idStorageVolumeMap =
           updateVolumesInPartition(partition); // TODO:GRZE: restoring volume state
       for (final String v : partitionVolumeMap.get(partition)) {
         try {
           final StorageVolume storageVolume = idStorageVolumeMap.get(v);
           volumeStateUpdate(v, storageVolume);
         } catch (final Exception ex) {
           LOG.error(ex);
           Logs.extreme().error(ex, ex);
         }
       }
     } catch (final Exception ex) {
       LOG.error(ex);
       Logs.extreme().error(ex, ex);
     }
   }
 }
Example #13
0
  @Test
  public void testStatVFS() throws Exception, VolumeNotFoundException {
    final String VOLUME_NAME_1 = "foobar";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME_1);

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

    StatVFS volumeVFS = volume.statFS(userCredentials);

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

    StatVFS mrcClientVFS = null;
    RPCResponse<StatVFS> resp = null;
    try {
      statvfsRequest input =
          statvfsRequest.newBuilder().setVolumeName(VOLUME_NAME_1).setKnownEtag(0).build();
      resp = mrcClient.statvfs(testEnv.getMRCAddress(), auth, userCredentials, input);
      mrcClientVFS = resp.get();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(volumeVFS);
    assertEquals(mrcClientVFS, volumeVFS);
  }
Example #14
0
 protected void indexTablePut(long recid, long offset) {
   if (tx) {
     modified[lockPos(recid)].put(recid, offset);
   } else {
     indexTable.ensureAvailable(recid * 8 + 8);
     indexTable.putLong(recid * 8, offset);
   }
 }
Example #15
0
 public static void main(String[] args) {
   Volume myV = new Volume();
   final Volume v2;
   v2 = myV.doStuff(myV);
   v2.v.size = 7;
   System.out.println(v2.size);
   // 4.) A.	 5
 }
Example #16
0
  @Test
  public void testToString() {
    // setup
    Volume volume1 = new Volume("owner", "vol", "inst", "device", VolumeState.CREATING, 0l);

    // assert
    assertTrue(volume1.toString().contains("owner"));
  }
Example #17
0
  @Test(enabled = true)
  public void testCreateTemplate() throws Exception {
    Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
    assertNotNull(zone);
    Iterable<Network> networks =
        client
            .getNetworkClient()
            .listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
    networks =
        Iterables.filter(
            networks,
            new Predicate<Network>() {
              @Override
              public boolean apply(@Nullable Network network) {
                return network != null && network.getState().equals("Implemented");
              }
            });
    assertEquals(Iterables.size(networks), 1);
    Network network = Iterables.getOnlyElement(networks, null);
    assertNotNull(network);

    // Create a VM and stop it
    Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
    vmForCreation =
        VirtualMachineClientLiveTest.createVirtualMachineInNetwork(
            network, templateId, client, jobComplete, virtualMachineRunning);
    assertTrue(
        jobComplete.apply(
            client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())),
        vmForCreation.toString());

    // Work out the VM's volume
    Set<Volume> volumes =
        client
            .getVolumeClient()
            .listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId()));
    assertEquals(volumes.size(), 1);
    Volume volume = Iterables.getOnlyElement(volumes);

    // Create a template
    CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
    AsyncCreateResponse response =
        client
            .getTemplateClient()
            .createTemplate(
                TemplateMetadata.builder()
                    .name(prefix + "-createTemplate")
                    .osTypeId(vmForCreation.getGuestOSId())
                    .displayText("jclouds live testCreateTemplate")
                    .build(),
                options);
    assertTrue(jobComplete.apply(response.getJobId()), vmForCreation.toString());
    createdTemplate =
        client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId());

    // Assertions
    assertNotNull(createdTemplate);
  }
Example #18
0
  @Override
  public String createVolume(int sizeGB, String snapshotId) {
    IaasProvider iaasInfo = getIaasProvider();

    ComputeServiceContext context = iaasInfo.getComputeService().getContext();

    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    String zone = ComputeServiceBuilderUtil.extractZone(iaasInfo);

    if (region == null || zone == null) {
      log.fatal(
          "Cannot create a new volume in the [region] : "
              + region
              + ", [zone] : "
              + zone
              + " of Iaas : "
              + iaasInfo);
      return null;
    }

    ElasticBlockStoreApi blockStoreApi =
        context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();

    Volume volume;
    if (StringUtils.isEmpty(snapshotId)) {
      if (log.isDebugEnabled()) {
        log.info("Creating a volume in the zone " + zone);
      }
      volume = blockStoreApi.createVolumeInAvailabilityZone(zone, sizeGB);
    } else {
      if (log.isDebugEnabled()) {
        log.info("Creating a volume in the zone " + zone + " from the shanpshot " + snapshotId);
      }
      volume = blockStoreApi.createVolumeFromSnapshotInAvailabilityZone(zone, snapshotId);
    }

    if (volume == null) {
      log.fatal(
          "Volume creation was unsuccessful. [region] : "
              + region
              + ", [zone] : "
              + zone
              + " of Iaas : "
              + iaasInfo);
      return null;
    }

    log.info(
        "Successfully created a new volume [id]: "
            + volume.getId()
            + " in [region] : "
            + region
            + ", [zone] : "
            + zone
            + " of Iaas : "
            + iaasInfo);
    return volume.getId();
  }
Example #19
0
  @Override
  protected <A> A get2(long recid, Serializer<A> serializer) {
    if (CC.ASSERT) assertReadLocked(recid);

    long offset = modified[lockPos(recid)].get(recid);
    if (offset == 0) {
      try {
        offset = indexTable.getLong(recid * 8);
      } catch (ArrayIndexOutOfBoundsException e) {
        // TODO this code should be aware if indexTable internals?
        throw new DBException.EngineGetVoid();
      }
    }

    if (offset == -3 || offset == -1) // null, preallocated or deleted
    return null;
    if (offset == 0) { // non existent
      throw new DBException.EngineGetVoid();
    }
    if (offset == -2) {
      // zero size record
      return deserialize(serializer, 0, new DataIO.DataInputByteArray(new byte[0]));
    }

    final long packedRecidSize = DataIO.packLongSize(longParitySet(recid));

    if (CC.ASSERT) {
      int instruction = vol.getUnsignedByte(offset);

      if (instruction != I_UPDATE && instruction != I_INSERT)
        throw new DBException.DataCorruption("wrong instruction " + instruction);

      long recid2 = vol.getPackedLong(offset + 1);

      if (packedRecidSize != recid2 >>> 60)
        throw new DBException.DataCorruption("inconsistent recid len");

      recid2 = longParityGet(recid2 & DataIO.PACK_LONG_RESULT_MASK);
      if (recid != recid2) throw new DBException.DataCorruption("recid does not match");
    }

    offset +=
        1
            + // instruction size
            packedRecidSize; // recid size

    // read size
    long size = vol.getPackedLong(offset);
    offset += size >>> 60;
    size = longParityGet(size & DataIO.PACK_LONG_RESULT_MASK);

    size -= 1; // normalize size
    if (CC.ASSERT && size <= 0) throw new DBException.DataCorruption("wrong size");

    DataInput input = vol.getDataInputOverlap(offset, (int) size);
    return deserialize(serializer, (int) size, input);
  }
Example #20
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);
      }
    }
  }
  protected Volume.Factory extendStoreVolumeFactory() {
    long sizeLimit = propsGetLong(Keys.sizeLimit, 0);
    String volume = props.getProperty(Keys.volume);
    if (Keys.volume_heap.equals(volume)) return Volume.memoryFactory(false, sizeLimit);
    else if (Keys.volume_offheap.equals(volume)) return Volume.memoryFactory(true, sizeLimit);

    File file = new File(props.getProperty(Keys.file));

    return Volume.fileFactory(propsGetBool(Keys.readOnly), propsGetRafMode(), file, sizeLimit);
  }
Example #22
0
 protected void logStackTrace() {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   new Exception().printStackTrace(new PrintStream(out));
   byte[] b = out.toByteArray();
   log.ensureAvailable(pos + 8 + b.length);
   log.putLong(pos, b.length);
   pos += 8;
   log.putData(pos, b, 0, b.length);
   pos += b.length;
 }
Example #23
0
  public CreateVolumeResponseType CreateVolume(final CreateVolumeType request)
      throws EucalyptusCloudException, AuthException {
    Context ctx = Contexts.lookup();
    Long volSize = request.getSize() != null ? Long.parseLong(request.getSize()) : null;
    final String snapId = request.getSnapshotId();
    String partition = request.getAvailabilityZone();

    if ((request.getSnapshotId() == null && request.getSize() == null)) {
      throw new EucalyptusCloudException("One of size or snapshotId is required as a parameter.");
    }

    if (snapId != null) {
      try {
        Transactions.find(Snapshot.named(null, snapId));
      } catch (ExecutionException ex) {
        throw new EucalyptusCloudException(
            "Failed to create volume because the referenced snapshot id is invalid: " + snapId);
      }
    }
    final Integer newSize = new Integer(request.getSize() != null ? request.getSize() : "-1");
    Exception lastEx = null;
    for (int i = 0; i < VOL_CREATE_RETRIES; i++) {
      try {
        final ServiceConfiguration sc =
            Topology.lookup(Storage.class, Partitions.lookupByName(partition));
        final UserFullName owner = ctx.getUserFullName();
        Function<Long, Volume> allocator =
            new Function<Long, Volume>() {

              @Override
              public Volume apply(Long size) {
                try {
                  return Volumes.createStorageVolume(
                      sc, owner, snapId, Ints.checkedCast(size), request);
                } catch (ExecutionException ex) {
                  throw Exceptions.toUndeclared(ex);
                }
              }
            };
        Volume newVol = RestrictedTypes.allocateMeasurableResource(newSize.longValue(), allocator);
        CreateVolumeResponseType reply = request.getReply();
        reply.setVolume(newVol.morph(new edu.ucsb.eucalyptus.msgs.Volume()));
        return reply;
      } catch (RuntimeException ex) {
        LOG.error(ex, ex);
        if (!(ex.getCause() instanceof ExecutionException)) {
          throw ex;
        } else {
          lastEx = ex;
        }
      }
    }
    throw new EucalyptusCloudException(
        "Failed to create volume after " + VOL_CREATE_RETRIES + " because of: " + lastEx, lastEx);
  }
Example #24
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());
  }
Example #25
0
  @Test
  public void testIsDeletedTrue() {
    // setup
    Volume volume = new Volume();

    // act
    volume.setStatus(VolumeState.BURIED);

    // assert
    assertTrue(volume.isDeleted());
  }
Example #26
0
  @Test
  public void testIsDeletedFalse() {
    // setup
    Volume volume = new Volume();

    // act
    volume.setStatus(VolumeState.DELETING);

    // assert
    assertFalse(volume.isDeleted());
  }
Example #27
0
  protected long countLongStackItems(long ioList) {
    long ret = 0;
    long v = index.getLong(ioList);

    while (true) {
      long next = v & MASK_OFFSET;
      if (next == 0) return ret;
      ret += v >>> 48;
      v = phys.getLong(next);
    }
  }
Example #28
0
  @Test
  public void testsetDeletedTrue() {
    // setup
    Volume volume = new Volume();

    // act
    volume.setDeleted(true);

    // assert
    assertTrue(volume.isDeleted());
    assertEquals(VolumeState.BURIED, volume.getStatus());
  }
Example #29
0
  protected void longStackPut(final long ioList, long offset, boolean recursive) {
    assert (disableLocks || structuralLock.isHeldByCurrentThread());
    assert (offset >>> 48 == 0);
    assert (ioList >= IO_FREE_RECID && ioList <= IO_USER_START) : "wrong ioList: " + ioList;

    long dataOffset = index.getLong(ioList);
    long pos = dataOffset >>> 48;
    dataOffset &= MASK_OFFSET;

    if (dataOffset == 0) { // empty list?
      // TODO allocate pages of mixed size
      // yes empty, create new page and fill it with values
      final long listPhysid = freePhysTake((int) LONG_STACK_PREF_SIZE, true, true) & MASK_OFFSET;
      if (listPhysid == 0) throw new AssertionError();
      // set previous Free Index List page to zero as this is first page
      // also set size of this record
      phys.putLong(listPhysid, LONG_STACK_PREF_SIZE << 48);
      // set  record
      phys.putSixLong(listPhysid + 8, offset);
      // and update index file with new page location
      index.putLong(ioList, (8L << 48) | listPhysid);
      if (maxUsedIoList <= ioList) maxUsedIoList = ioList;
    } else {
      long next = phys.getLong(dataOffset);
      long size = next >>> 48;
      next &= MASK_OFFSET;
      assert (pos + 6 <= size);
      if (pos + 6 == size) { // is current page full?
        long newPageSize = LONG_STACK_PREF_SIZE;
        if (ioList == size2ListIoRecid(LONG_STACK_PREF_SIZE)) {
          // TODO double allocation fix needs more investigation
          newPageSize = LONG_STACK_PREF_SIZE_ALTER;
        }
        // yes it is full, so we need to allocate new page and write our number there
        final long listPhysid = freePhysTake((int) newPageSize, true, true) & MASK_OFFSET;
        if (listPhysid == 0) throw new AssertionError();

        // set location to previous page and set current page size
        phys.putLong(listPhysid, (newPageSize << 48) | (dataOffset & MASK_OFFSET));

        // set the value itself
        phys.putSixLong(listPhysid + 8, offset);

        // and update index file with new page location and number of records
        index.putLong(ioList, (8L << 48) | listPhysid);
      } else {
        // there is space on page, so just write offset and increase the counter
        pos += 6;
        phys.putSixLong(dataOffset + pos, offset);
        index.putLong(ioList, (pos << 48) | dataOffset); // TODO update just 2 bytes
      }
    }
  }
Example #30
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);
 }