MIT6.824 Lab 3: Fault-tolerant Key/Value Service (1)

本文详细介绍了如何使用Raft库实现容错key-value服务的Part A,包括Put(), Append()和Get()的RPC调用处理,以及客户端与服务器之间的交互。实验中,服务端通过Raft共识处理操作,客户端通过并发RPC调用来测试系统的正确性。关键在于服务端的execOp函数,它根据操作类型提交到Raft并处理结果。" 106721827,8078799,理解BFS与DFS遍历方法,"['算法', '数据结构', '二叉树']

Introduction
  在这次实验中,我们将使用Lab2的Raft库来实现容错的key-value存储服务。
  存储系统将由客户端和key/value服务器,每个key/value服务器使用Raft节点。客户端发送Put(), Append()和Get()的RPCs 到key/value服务器(kvraft),然后将这些RPC调用存入Raft的log中并按序执行。客户端可以向任何kvraft服务器发送RPC请求,但是如果该服务器不是Raft领导者或者请求失败超时,则需要重新发送给另外一个。假如操作被committed到Raft的log中并应用到状态机中,那么它的结果需要反馈到客户端。假如commit操作失败(比如领导者被替换),客户端必须重新发送请求。
  本次实验分为2部分。在Part A,我们要实现key/value服务,无需考虑日志长度。在Part B,我们需要考虑日志长度,实现Snapshot。

Part A: Key/value service without log compaction
  该服务支持3种RPC调用:Put(key, value),Append(key, arg)和Get(key)。Put()函数替换key对应的value,Append(key, arg)函数将arg增加到key对应的value,Get()函数获取key对应的value。Append值到不存在的key,就理解为Put函数。

具体实现
  与前面博客一样,我们先从测试代码出发,一步步实现具体函数。
  首先是TestBasic测试函数,该测试函数检查在无Fault情况下单客户端操作的正确性。其中涉及到了1个重要的测试函数GenericTest。

func GenericTest(t *testing.T, tag string, nclients int, unreliable bool, crash bool, partitions bool, maxraftstate int) {
    const nservers = 5
    cfg := make_config(t, tag, nservers, unreliable, maxraftstate)
    defer cfg.cleanup()

    ck := cfg.makeClient(cfg.All())

    done_partitioner := int32(0)
    done_clients := int32(0)
    ch_partitioner := make(chan bool)
    clnts := make([]chan int, nclients)
    for i := 0; i < nclients; i++ {
        clnts[i] = make(chan int)
    }
    for i := 0; i < 3; i++ {
        // log.Printf("Iteration %v\n", i)
        atomic.StoreInt32(&done_clients, 0)
        atomic.StoreInt32(&done_partitioner, 0)
        go spawn_clients_and_wait(t, cfg, nclients, func(cli int, myck *Clerk, t *testing.T) {
            j := 0
            defer func() {
                clnts[cli] <- j
            }()
            last := ""
            key := strconv.Itoa(cli)
            myck.Put(key, last)
            for atomic.LoadInt32(&done_clients) == 0 {
                if (rand.Int() % 1000) < 500 {
                    nv := "x " + strconv.Itoa(cli) + " " + strconv.Itoa(j) + " y"
                    // log.Printf("%d: client new append %v\n", cli, nv)
                    myck.Append(key, nv)
                    last = NextValue(last, nv)
                    j++
                } else {
                    // log.Printf("%d: client new get %v\n", cli, key)
                    v := myck.Get(key)
                    if v != last {
                        log.Fatalf("get wrong value, key %v, wanted:\n%v\n, got\n%v\n", key, last, v)
                    }
                }
            }
        })

        if partitions {
            // Allow the clients to perform some operations without interruption
            time.Sleep(1
没连接上adb的log Line 756: 09-04 15:51:07.495407 656 671 I keystore2: system/security/keystore2/src/maintenance.rs:343 - apex modules += com.android.adbd version 360527520 Line 909: 09-04 15:51:07.885328 813 813 D aconfigd_mainline: aconfigd_rust::aconfigd: start initialize com.android.adbd flags Line 1059: 09-04 15:51:08.065497 817 817 D vold_prepare_subdirs: Setting up mode 771 uid 0 gid 1000 context u:object_r:apex_module_data_file:s0 on path: /data/misc_de/0/apexdata/com.android.adbd Line 23508: 09-04 15:51:18.085916 1754 1754 D CompatConfig: No directory /apex/com.android.adbd/etc/compatconfig, skipping Line 25057: 09-04 15:51:19.382368 1754 1754 W PackageManager: No package known for package restrictions com.google.android.adbd Line 25417: 09-04 15:51:19.503966 1754 1754 D PackageManager: Directories scanned as system partitions: [/system:0, /vendor:524288, /odm:4194304, /oem:262144, /product:1048576, /system_ext:2097152, /my_product/non_overlay:1048576, /my_stock/non_overlay:1048576, /mnt/opex/com.oplus.odmf@16000005:2097152, /mnt/opex/com.oplus.moduleservices@15000014:2097152, /mnt/opex/com.oplus.fancyIconLoader@1000000:2097152, /mnt/opex/com.oplus.NetworkAssistSys@16000021:2097152, /mnt/opex/com.oplus.CustCore@16000001:2097152, /my_company:1048576, /my_carrier:1048576, /my_bigball:1048576, /my_product/cust/IN:1048576, /apex/com.android.rkpd:41943040, /apex/com.android.tethering:41943040, /apex/com.android.crashrecovery:41943040, /apex/com.android.profiling:41943040, /apex/com.android.healthfitness:41943040, /apex/com.android.mediaprovider:41943040, /apex/com.android.virt:41943040, /apex/com.android.os.statsd:41943040, /apex/com.android.wifi:41943040, /apex/com.android.devicelock:41943040, /apex/com.android.ipsec:41943040, /apex/com.android.extservices:41943040, /apex/com.android.uprobestats:41943040, /apex/com.android.art:41943040, /apex/com.android.vndk.v33:44040192, /apex/com.android.resolv:41943040, /apex/com.android.cellbroadcast:41943040, /apex/com.android.sdkext:41943040, /apex/com.android.adbd:41943040, /apex/com.android.adservices:41943040, /apex/com.android.i18n:41943040, /apex/com.android.conscrypt:41943040, /apex/com.android.neuralnetworks:41943040, /apex/com.android.runtime:41943040, /apex/com.android.ondevicepersonalization:41943040, /apex/com.android.apex.cts.shim:41943040, /apex/com.android.media.swcodec:41943040, /apex/com.android.uwb:41943040, /apex/com.android.compos:44040192, /apex/com.android.tzdata:41943040, /apex/com.android.permission:41943040, /apex/com.android.configinfrastructure:41943040, /apex/com.android.scheduling:41943040, /apex/com.android.media:41943040, /apex/com.android.appsearch:41943040] Line 25450: 09-04 15:51:19.561963 1754 1754 I PackageManager: /data/apex/decompressed/com.android.adbd@360527520.decompressed.apex changed; collecting certs Line 25451: 09-04 15:51:19.563661 1754 1754 E PackageManagerServiceUtilsExtImpl: Fix up user restrict data of pkg: com.google.android.adbd 连上adb的log Line 279: 09-04 16:20:12.580 659 673 I keystore2: system/security/keystore2/src/maintenance.rs:343 - apex modules += com.android.adbd version 360527520 Line 445: 09-04 16:20:18.616 1123 1155 I adbd : opening control endpoint /dev/usb-ffs/adb/ep0 Line 3593: 09-04 16:20:19.389 1123 1123 I adbd : adbd_auth: loading keys from /data/misc/adb/adb_keys Line 3593: 09-04 16:20:19.389 1123 1123 I adbd : adbd_auth: loading keys from /data/misc/adb/adb_keys Line 14945: 09-04 16:20:23.062 1721 1721 D CompatConfig: No directory /apex/com.android.adbd/etc/compatconfig, skipping Line 16672: 09-04 16:20:24.318 1721 1721 W PackageManager: No package known for package restrictions com.google.android.adbd Line 17030: 09-04 16:20:24.433 1721 1721 D PackageManager: Directories scanned as system partitions: [/system:0, /vendor:524288, /odm:4194304, /oem:262144, /product:1048576, /system_ext:2097152, /my_product/non_overlay:1048576, /my_stock/non_overlay:1048576, /mnt/opex/com.oplus.odmf@16000005:2097152, /mnt/opex/com.oplus.moduleservices@15000014:2097152, /mnt/opex/com.oplus.fancyIconLoader@1000000:2097152, /mnt/opex/com.oplus.NetworkAssistSys@16000021:2097152, /mnt/opex/com.oplus.CustCore@16000001:2097152, /my_company:1048576, /my_carrier:1048576, /my_bigball:1048576, /my_product/cust/IN:1048576, /apex/com.android.media:41943040, /apex/com.android.adbd:41943040, /apex/com.android.extservices:41943040, /apex/com.android.ondevicepersonalization:41943040, /apex/com.android.tethering:41943040, /apex/com.android.media.swcodec:41943040, /apex/com.android.os.statsd:41943040, /apex/com.android.mediaprovider:41943040, /apex/com.android.resolv:41943040, /apex/com.android.art:41943040, /apex/com.android.adservices:41943040, /apex/com.android.scheduling:41943040, /apex/com.android.crashrecovery:41943040, /apex/com.android.compos:44040192, /apex/com.android.sdkext:41943040, /apex/com.android.apex.cts.shim:41943040, /apex/com.android.uprobestats:41943040, /apex/com.android.uwb:41943040, /apex/com.android.ipsec:41943040, /apex/com.android.permission:41943040, /apex/com.android.i18n:41943040, /apex/com.android.conscrypt:41943040, /apex/com.android.profiling:41943040, /apex/com.android.healthfitness:41943040, /apex/com.android.rkpd:41943040, /apex/com.android.appsearch:41943040, /apex/com.android.neuralnetworks:41943040, /apex/com.android.tzdata:41943040, /apex/com.android.wifi:41943040, /apex/com.android.vndk.v33:44040192, /apex/com.android.cellbroadcast:41943040, /apex/com.android.virt:41943040, /apex/com.android.runtime:41943040, /apex/com.android.devicelock:41943040, /apex/com.android.configinfrastructure:41943040] Line 17054: 09-04 16:20:24.486 1721 1721 I PackageManager: /data/apex/decompressed/com.android.adbd@360527520.decompressed.apex changed; collecting certs Line 17055: 09-04 16:20:24.488 1721 1721 E PackageManagerServiceUtilsExtImpl: Fix up user restrict data of pkg: com.google.android.adbd Line 17771: 09-04 16:20:25.762 1721 1721 D PackageManager: No files in app dir /apex/com.android.adbd/priv-app Line 17772: 09-04 16:20:25.762 1721 1721 D PackageManager: No files in app dir /apex/com.android.adbd/app Line 22926: 09-04 16:20:29.047 1721 1942 I UsbDeviceManager: failed to write to /sys/class/android_usb/android0/f_rndis/ethaddr Line 22928: 09-04 16:20:29.048 1721 1942 D UsbPortManager: Querying USB Gadget HAL version Line 22946: 09-04 16:20:29.054 1721 1942 I UsbPortManager: USB Gadget HAL HIDL present Line 22958: 09-04 16:20:29.056 1721 1895 I UsbDeviceManager: Usb gadget hal service started android.hardware.usb.gadget@1.0::IUsbGadget default Line 22964: 09-04 16:20:29.058 1721 1942 D UsbDeviceManager: getInstance done Line 22987: 09-04 16:20:29.064 1721 1942 I UsbDeviceManager: mResetUsbGadgetDisableDebounce:false connected:1configured:1 Line 22989: 09-04 16:20:29.064 1721 1841 I UsbDeviceManager: USB Gadget HAL HIDL version: 11 Line 22990: 09-04 16:20:29.064 1721 1841 I UsbDeviceManager: handleMessage MSG_UPDATE_STATE mConnected:true mConfigured:true
09-05
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值