TEST_P(DtlCheckerTest, auto_recovery)
{
    auto ns_ptr = make_random_namespace();

    const backend::Namespace& ns = ns_ptr->ns();

    SharedVolumePtr v = newVolume("vol1",
                          ns);

    const auto port = get_next_foc_port();
    ASSERT_THROW(v->setFailOverCacheConfig(FailOverCacheConfig(FailOverCacheTestSetup::host(),
                                                               port,
                                                               GetParam().foc_mode())),
                 fungi::IOException);

    ASSERT_EQ(VolumeFailOverState::DEGRADED,
              v->getVolumeFailOverState());

    auto foc_ctx(start_one_foc());
    ASSERT_EQ(port,
              foc_ctx->port());

    boost::this_thread::sleep_for(2 * dtl_check_interval_);

    ASSERT_EQ(VolumeFailOverState::OK_SYNC,
              v->getVolumeFailOverState());
}
TEST_P(BigReadWriteTest, bigReadsOnFull)
{
    auto ns_ptr = make_random_namespace();
    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns());

    SCOPED_BLOCK_BACKEND(*v);

    size_t csz = v->getClusterSize();
    size_t lba_size = v->getLBASize();

    const std::string pattern(csz,'a');
    size_t scoMul = v->getSCOMultiplier();
    for(size_t i = 0;i < 50*scoMul; ++i)
    {
        writeToVolume(*v, i* csz / lba_size, csz, pattern);
    }

    // Stop here to manually delete sco's to check error handling
    for(size_t i = 0; i < scoMul; ++i)
    {
        checkVolume(*v,0, csz*scoMul, pattern);
    }

}
TEST_P(SnapshotRestoreTest, snapshot_restoration_on_a_clone)
{
    const auto wrns_parent(make_random_namespace());
    const std::string parent_name(wrns_parent->ns().str());

    SharedVolumePtr parent = newVolume(VolumeId(parent_name),
                               be::Namespace(parent_name));

    const std::string pattern1("before-parent-snapshot");

    writeToVolume(*parent,
                  0,
                  parent->getClusterSize(),
                  pattern1);

    const SnapshotName parent_snap("parent-snapshot");
    parent->createSnapshot(parent_snap);

    waitForThisBackendWrite(*parent);

    const auto wrns_clone(make_random_namespace());
    const std::string clone_name(wrns_clone->ns().str());

    SharedVolumePtr clone = createClone(clone_name,
                                be::Namespace(clone_name),
                                be::Namespace(parent_name),
                                parent_snap);

    const std::string pattern2("before-clone-snapshot");

    writeToVolume(*clone,
                  0,
                  clone->getClusterSize(),
                  pattern2);

    const SnapshotName clone_snap("clone-snapshot");
    clone->createSnapshot(clone_snap);

    waitForThisBackendWrite(*clone);

    const std::string pattern3("after-clone-snapshot");

    writeToVolume(*clone,
                  0,
                  clone->getClusterSize(),
                  pattern3);

    checkVolume(*clone,
                0,
                clone->getClusterSize(),
                pattern3);

    restoreSnapshot(*clone,
                    clone_snap);

    checkVolume(*clone,
                0,
                clone->getClusterSize(),
                pattern2);
}
    void
    startVolume()
    {
        ASSERT(not vol_);
        startVolManager();
        vol_ = newVolume("volume1",
			 getNamespace());
        ASSERT(vol_);
        dStore_ = vol_->getDataStore();
        ASSERT(dStore_);

    }
void VlcWidgetVolumeSlider::setVolume(const int &volume)
{
    if (_currentVolume == volume)
        return;

    lock();

    _currentVolume = volume;
    setValue(_currentVolume);

    emit newVolume(_currentVolume);

    unlock();
}
TEST_P(SnapshotRestoreTest, TestFailOver)
{
    auto foc_ctx(start_one_foc());
    auto ns_ptr = make_random_namespace();
    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns(),
                          VolumeSize((1 << 18) * 512),
                          SCOMultiplier(1));

    v->setFailOverCacheConfig(foc_ctx->config(GetParam().foc_mode()));

    VolumeConfig cfg = v->get_config();
    v->createSnapshot(SnapshotName("snap0"));

    for(int i = 0; i < 5; ++i)
    {
        writeToVolume(*v,
                      0,
                      4096,
                      "a");
    }


    waitForThisBackendWrite(*v);
    v->restoreSnapshot(SnapshotName("snap0"));

    for(int i = 0; i < 7; ++i)
    {
        writeToVolume(*v,
                      8,
                      4096,
                      "d");
    }

    flushFailOverCache(*v);
    destroyVolume(v,
                  DeleteLocalData::T,
                  RemoveVolumeCompletely::F);

    SharedVolumePtr v1 = 0;
    v1 = getVolume(VolumeId("volume1"));
    ASSERT_FALSE(v1);
    restartVolume(cfg);
    v1 = getVolume(VolumeId("volume1"));

    ASSERT_TRUE(v1 != nullptr);
    checkVolume(*v1,0,4096, "\0");
    checkVolume(*v1,8,4096, "d");
    checkCurrentBackendSize(*v1);
}
Exemple #7
0
void VlcWidgetVolumeSlider::setVolume(const int &volume)
{
    if (_currentVolume == volume)
        return;

    lock();

    _currentVolume = volume;
    _slider->setValue(_currentVolume);
    _label->setText(QString().number(_currentVolume));

    emit newVolume(_currentVolume);

    unlock();
}
TEST_P(BigReadWriteTest, bigReadsOnEmpty)
{
    auto ns_ptr = make_random_namespace();

    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns());

    size_t csz = v->getClusterSize();
    const std::string pattern(csz,'\0');
    size_t scoMul = v->getSCOMultiplier();

    for(size_t i = 0; i < scoMul; ++i)
    {
        checkVolume(*v,0, csz*scoMul, pattern);
    }
}
TEST_P(BigReadWriteTest, OneBigWriteOneBigRead)
{
    auto ns_ptr = make_random_namespace();

    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                                  ns_ptr->ns());

    SCOPED_BLOCK_BACKEND(*v);

    size_t csz = v->getClusterSize();

    const std::string pattern(csz,'a');
    size_t scoMul = v->getSCOMultiplier();
    writeToVolume(*v, 0, csz * scoMul, pattern);

    // Stop here to manually delete sco's to check error handling
    checkVolume(*v,0, csz*scoMul, pattern);

}
TEST_P(SnapshotRestoreTest, RestoreAndWriteAgain1)
{
    auto ns_ptr = make_random_namespace();
    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns(),
                          VolumeSize(1 << 26),
                          SCOMultiplier(1));

    const std::string pattern("e-manual");

    v->createSnapshot(SnapshotName("snap1"));
    waitForThisBackendWrite(*v);

    writeToVolume(*v, 0, 5 * 4096, pattern);
    waitForThisBackendWrite(*v);

    restoreSnapshot(*v,"snap1");

    writeToVolume(*v, 0, 4*4096, pattern);
    waitForThisBackendWrite(*v);
    checkCurrentBackendSize(*v);
}
TEST_P(SnapshotRestoreTest, HaltOnError)
{
    auto ns_ptr = make_random_namespace();
    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns());

    const std::string pattern1("blah");

    const TLogId tlog_id(v->getSnapshotManagement().getCurrentTLogId());

    writeToVolume(*v, 0, 4096, pattern1);
    v->createSnapshot(SnapshotName("snap1"));
    waitForThisBackendWrite(*v);

    EXPECT_THROW(restoreSnapshot(*v, "snap42"),
                 std::exception);
    EXPECT_FALSE(v->is_halted());

    v->getBackendInterface()->remove(boost::lexical_cast<std::string>(tlog_id));
    EXPECT_THROW(restoreSnapshot(*v, "snap1"),
                 std::exception);
    EXPECT_TRUE(v->is_halted());
}
TEST_P(PrefetchThreadTest, test_one)
{
    auto ns_ptr = make_random_namespace();

    const backend::Namespace& ns = ns_ptr->ns();

    Volume* v = newVolume("v1",
			  ns);

    const size_t numwrites = 20;
    for(size_t i = 0; i < numwrites; ++i)
    {
        writeToVolume(v,
                      0,
                      4096,
                      "Superflous");
    }

    syncToBackend(v);

    destroyVolume(v,
                  DeleteLocalData::T,
                  RemoveVolumeCompletely::F);
}
 SharedVolumePtr
 make_volume(const be::BackendTestSetup::WithRandomNamespace& wrns)
 {
     return newVolume(make_volume_params(wrns));
 }
Exemple #14
0
/*
 *  Items needed:
 *   mr.PoolId must be set
 *   mr.StorageId should also be set
 *   mr.ScratchPoolId could be set (used if create==true)
 *   jcr->wstore
 *   jcr->db
 *   jcr->pool
 *   MEDIA_DBR mr with PoolId set
 *   create -- whether or not to create a new volume
 */
int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,             
                                bool create, bool prune)
{
   int retry = 0;
   bool ok;
   bool InChanger;
   STORE *store = jcr->wstore;

   bstrncpy(mr->MediaType, store->media_type, sizeof(mr->MediaType));
   Dmsg3(100, "find_next_vol_for_append: JobId=%u PoolId=%d, MediaType=%s\n", 
         (uint32_t)jcr->JobId, (int)mr->PoolId, mr->MediaType);
   /*
    * If we are using an Autochanger, restrict Volume
    *   search to the Autochanger on the first pass
    */
   InChanger = store->autochanger;
   /*
    * Find the Next Volume for Append
    */
   db_lock(jcr->db);
   for ( ;; ) {
      bstrncpy(mr->VolStatus, "Append", sizeof(mr->VolStatus));  /* want only appendable volumes */
      /*
       *  1. Look for volume with "Append" status.
       */
      ok = db_find_next_volume(jcr, jcr->db, index, InChanger, mr);

      if (!ok) {
         Dmsg4(150, "after find_next_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
               ok, index, InChanger, mr->VolStatus);
         /*
          * 2. Try finding a recycled volume
          */
         ok = find_recycled_volume(jcr, InChanger, mr);
         Dmsg2(150, "find_recycled_volume ok=%d FW=%d\n", ok, mr->FirstWritten);
         if (!ok) {
            /*
             * 3. Try recycling any purged volume
             */
            ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
            if (!ok) {
               /*
                * 4. Try pruning Volumes
                */
               if (prune) {
                  Dmsg0(150, "Call prune_volumes\n");
                  prune_volumes(jcr, InChanger, mr);
               }
               ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
               if (!ok && create) {
                  Dmsg4(150, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
                        ok, index, InChanger, mr->VolStatus);
                  /*
                   * 5. Try pulling a volume from the Scratch pool
                   */ 
                  ok = get_scratch_volume(jcr, InChanger, mr);
                  Dmsg4(150, "after get scratch volume ok=%d index=%d InChanger=%d Vstat=%s\n",
                        ok, index, InChanger, mr->VolStatus);
               }
               /*
                * If we are using an Autochanger and have not found
                * a volume, retry looking for any volume. 
                */
               if (!ok && InChanger) {
                  InChanger = false;
                  continue;           /* retry again accepting any volume */
               }
            }
         }


         if (!ok && create) {
            /*
             * 6. Try "creating" a new Volume
             */
            ok = newVolume(jcr, mr);
         }
         /*
          *  Look at more drastic ways to find an Appendable Volume
          */
         if (!ok && (jcr->pool->purge_oldest_volume ||
                     jcr->pool->recycle_oldest_volume)) {
            Dmsg2(200, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
                jcr->pool->purge_oldest_volume, jcr->pool->recycle_oldest_volume);
            /* Find oldest volume to recycle */
            ok = db_find_next_volume(jcr, jcr->db, -1, InChanger, mr);
            Dmsg1(200, "Find oldest=%d Volume\n", ok);
            if (ok && prune) {
               UAContext *ua;
               Dmsg0(200, "Try purge Volume.\n");
               /*
                * 7.  Try to purging oldest volume only if not UA calling us.
                */
               ua = new_ua_context(jcr);
               if (jcr->pool->purge_oldest_volume && create) {
                  Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
                  ok = purge_jobs_from_volume(ua, mr);
               /*
                * 8. or try recycling the oldest volume
                */
               } else if (jcr->pool->recycle_oldest_volume) {
                  Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
                  ok = prune_volume(ua, mr);
               }
               free_ua_context(ua);
               if (ok) {
                  ok = recycle_volume(jcr, mr);
                  Dmsg1(400, "Recycle after purge oldest=%d\n", ok);
               }
            }
         }
      }
      Dmsg2(100, "VolJobs=%d FirstWritten=%d\n", mr->VolJobs, mr->FirstWritten);
      if (ok) {
         /* If we can use the volume, check if it is expired */
         if (has_volume_expired(jcr, mr)) {
            if (retry++ < 200) {            /* sanity check */
               continue;                    /* try again from the top */
            } else {
               Jmsg(jcr, M_ERROR, 0, _(
"We seem to be looping trying to find the next volume. I give up.\n"));
            }
         }
      }
      break;
   } /* end for loop */
   db_unlock(jcr->db);
   Dmsg1(150, "return ok=%d find_next_vol\n", ok);
   return ok;
}
TEST_P(PrefetchThreadTest, test_two)
{
    // backend::Namespace n1;
    auto ns_ptr = make_random_namespace();

    const backend::Namespace& n1 = ns_ptr->ns();

    Volume* v = newVolume("v1",
                          n1);
    // Y42 put in VolManagerTestSetup
    const VolumeConfig cfg = v->get_config();
    const uint64_t scoSize = cfg.getSCOSize();


    const size_t numwrites = 20;
    for(size_t i = 0; i < numwrites; ++i)
    {
        writeToVolume(v,
                      0,
                      scoSize,
                      "Superflous");
    }

    syncToBackend(v);

    SCONameList list;

    VolManager::get()->getSCOCache()->getSCONameList(n1,
                                        list,
                                        true);

    ASSERT_EQ(numwrites, list.size());

    for(SCONameList::const_iterator it = list.begin();
        it != list.end();
        ++it)
    {
        VolManager::get()->getSCOCache()->removeSCO(n1,
                                       *it,
                                       false);
    }

    {
        SCONameList list;
        VolManager::get()->getSCOCache()->getSCONameList(n1,
                                                         list,
                                                         true);
        ASSERT_TRUE(list.empty());
    }
    //fill the cache with 1 SCO
    SCONameList::const_iterator it = list.begin();
    v->getPrefetchData().addSCO(*it, 1);
    ++it;

    //make sure cachedXValMin_ is set
    VolManager::get()->getSCOCache()->cleanup();

    //make sure next SCO's with low sap are also prefetched as cache is not full
    float sap = 0.01;
    for( ; it != list.end(); ++it)
    {
        v->getPrefetchData().addSCO(*it, sap);
        sap *= 0.9;
    }

    SCONameList list2;
    size_t counter = 0;

    while(list2.size() != numwrites and counter < 60)
    {
        boost::this_thread::sleep(boost::posix_time::seconds(1));
        list2.clear();
        ++counter;
        VolManager::get()->getSCOCache()->getSCONameList(n1,
                                                         list2,
                                                         true);
    }

    ASSERT_EQ(numwrites, list2.size());
    destroyVolume(v,
                  DeleteLocalData::T,
                  RemoveVolumeCompletely::F);
}
TEST_P(SnapshotRestoreTest, SimpleRestore)
{
    auto ns_ptr = make_random_namespace();
    SharedVolumePtr v = newVolume(VolumeId("volume1"),
                          ns_ptr->ns());

    const std::string pattern1("Frederik");

    writeToVolume(*v, 0, 4096, pattern1);
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snap1"));

    const std::string pattern2("Frederik");

    writeToVolume(*v, 0, 4096, pattern2);
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snap2"));


    const std::string pattern3("Arne");

    writeToVolume(*v, 0, 4096, pattern3);
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snap3"));

    const std::string pattern4("Bart");

    writeToVolume(*v, 0, 4096, pattern4);
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snap4"));

    const std::string pattern5("Wouter");
    writeToVolume(*v, 0, 4096, pattern5);

    checkVolume(*v,0,4096,pattern5);
    waitForThisBackendWrite(*v);

    EXPECT_NO_THROW(restoreSnapshot(*v,
                                    "snap4"));

    checkVolume(*v,0,4096,pattern4);
    writeToVolume(*v, 0, 4096, "Bollocks");
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snapper"));
    waitForThisBackendWrite(*v);

    EXPECT_NO_THROW(restoreSnapshot(*v,
                                    "snap3"));

    checkVolume(*v,0,4096,pattern3);
    writeToVolume(*v, 0, 4096, "Bollocks");
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snapper"));
    waitForThisBackendWrite(*v);

    EXPECT_NO_THROW(restoreSnapshot(*v,
                                    "snap2"));

    checkVolume(*v,0,4096,pattern2);
    writeToVolume(*v, 0, 4096, "Bollocks");
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snapper"));
    waitForThisBackendWrite(*v);

    EXPECT_NO_THROW(restoreSnapshot(*v,
                                    "snap1"));

    checkVolume(*v,0,4096,pattern1);
    writeToVolume(*v, 0, 4096, "Bollocks");
    waitForThisBackendWrite(*v);
    v->createSnapshot(SnapshotName("snapper"));
    waitForThisBackendWrite(*v);
    checkCurrentBackendSize(*v);
}