Coder Social home page Coder Social logo

Comments (1)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024

已经进行了修复,效率有所提升。

测试概述
========
revise 前快照图如下:

       T0                                        T1                               T2                              T3
|---------------------------|          |--------------------------|         
|------------------------|         |---------------------|
|     null  |     T0      |          |     T0 |    T1        |         |    T1  
 |    T2     |         |    T2  |    T3    |
|---------------------------|          |--------------------------|         
|------------------------|         |---------------------|    

                                                                                     T4
                                                                           |-------------------------|
                                                                           |     T1   |     T4    |
                                                                           |-------------------------|                 ..................
revise 后的快照图如下:(我们这里删除了 T1)


            T0                                       T2                              T3
|---------------------------|               |------------------------|         
|---------------------|
|     null  |     T0      |               |    T0   |    T2     |         |    
T2  |    T3    |
|---------------------------|               |------------------------|         
|---------------------|    

                                                                                     T4
                                                                           |-------------------------|
                                                                           |     T0   |     T4    |
                                                                           |-------------------------|                 ..................





注意:上图的第一个域表示 up snapshot name, 第二个域表示 
current snapshot name。



测试代码
========

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#define HLFS_FILE_NAME_MAX            (80)

struct snapshot {
    uint64_t timestamp;
    uint64_t inode_addr;
    char sname[HLFS_FILE_NAME_MAX];
    char up_sname[HLFS_FILE_NAME_MAX]; /* for tree style snapshot */
} __attribute__((packed));


/* load all snapshot will remove del snapshot and revise relation upname */
static void predicate_same_upname_snapshot(gpointer key,gpointer value,gpointer 
user_data){

        g_message("enter func %s", __func__);
       char * ss_name = (char*)key;
       struct snapshot *ss = (struct snapshot*)value;
       struct snapshot *del_ss = (struct snapshot *)user_data;
       if(g_strcmp0(ss->up_sname,del_ss->sname) == 0){
           snprintf(ss->up_sname, HLFS_FILE_NAME_MAX, "%s", del_ss->up_sname);

       }
        g_message("leave func %s", __func__);
       return ;

}

static void revise_snapshot_relation(GHashTable *ss_hashtable,GList 
*remove_list){
    g_message("enter func %s", __func__);
     int i = 0;
     g_message("del list length is %d", g_list_length(remove_list));
     for(i = 0; i < g_list_length(remove_list); i++){
        char * ss_name = g_list_nth_data(remove_list,i);
        struct snapshot *ss = g_hash_table_lookup(ss_hashtable,ss_name);
        g_message("99 dbg del ss %s", ss->sname);
        g_assert(ss!=NULL);
        char *up_ss_name = ss->up_sname;
        g_hash_table_foreach (ss_hashtable,predicate_same_upname_snapshot,ss);
        g_hash_table_remove(ss_hashtable, ss->sname);

     }
    g_message("leave func %s", __func__);
     return ;
}

int main(int argc, char **argv) {
    int i = 0;
    char up_sname[128];
    memset(up_sname, 0, 128);
    struct snapshot ss[4];
    memset(ss, 0, 4 * sizeof(struct snapshot));

    GHashTable *ss_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    for (i = 0; i < 4; i++) {
        ss[i].timestamp = i;
        ss[i].inode_addr = i;
        sprintf(ss[i].sname, "%s%d", "T", i);
        sprintf(ss[i].up_sname, "%s", up_sname);
        memset(up_sname, 0, 128);
        strcpy(up_sname, ss[i].sname);
        g_hash_table_insert(ss_hashtable, ss[i].sname, &ss[i]);
    }
    struct snapshot _ss;
    memset(&_ss, 0, sizeof(struct snapshot));
    _ss.timestamp = 0;
    _ss.inode_addr = 0;
    sprintf(_ss.sname, "%s", "T4");
    sprintf(_ss.up_sname, "%s", "T1");
    g_hash_table_insert(ss_hashtable, _ss.sname, &_ss);

    GList *to_remove_ss_list = NULL;
    to_remove_ss_list = g_list_append(to_remove_ss_list, "T1");
- Show quoted text -
** Message: leave func revise_snapshot_relation
** Message: 99 dbg
snapshot 0 is -------------
name is T0
up name is
snapshot 1 is -------------
name is T4
up name is T0

snapshot 2 is -------------
name is T3
up name is T2
snapshot 3 is -------------
name is T2
up name is T0 

Original comment by [email protected] on 30 Jan 2012 at 2:49

  • Changed state: Fixed

from cloudxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.