valeriansaliou / bloom

:cherry_blossom: HTTP REST API caching middleware, to be used between load balancers and REST API workers.

Home Page:https://crates.io/crates/bloom-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi proxy.shard always set to first

rongfengliang opened this issue · comments

Can't get multi proxy.shard config correct because hard code for set proxy

fn map_shards() -> [Option<Uri>; MAX_SHARDS as usize] {
    // Notice: this array cannot be initialized using the short format, as hyper::Uri doesnt \
    //   implement the Copy trait, hence the ugly hardcoded initialization vector w/ Nones.
    let mut shards = [
        None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
        None,
    ];

    for shard in &APP_CONF.proxy.shard {
        // Shard number overflows?
        if shard.shard >= MAX_SHARDS {
            panic!("shard number overflows maximum of {} shards", MAX_SHARDS);
        }

        // Store this shard
        shards[shard.shard as usize] = Some(
            format!(
                "http://{}:{}",
               // always set to first 
                APP_CONF.proxy.shard[0].host, APP_CONF.proxy.shard[0].port
            )

            .parse()
            .expect("could not build shard uri"),
        );
    }

    shards
}

should be


fn map_shards() -> [Option<Uri>; MAX_SHARDS as usize] {
    // Notice: this array cannot be initialized using the short format, as hyper::Uri doesnt \
    //   implement the Copy trait, hence the ugly hardcoded initialization vector w/ Nones.
    let mut shards = [
        None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
        None,
    ];

    for shard in &APP_CONF.proxy.shard {
        // Shard number overflows?
        if shard.shard >= MAX_SHARDS {
            panic!("shard number overflows maximum of {} shards", MAX_SHARDS);
        }

        // Store this shard
        shards[shard.shard as usize] = Some(
            format!(
                "http://{}:{}",
                shard.host, shard.port
            )
            .parse()
            .expect("could not build shard uri"),
        );
    }

    shards
}

Thanks for the report, it looks like a dumb mistake from my end. I'm fixing this right now.

This should be fixed now, can you try building master and let me know if your multi-shard setup works now?

@valeriansaliou thanks,it works