MyCATApache/Mycat-Server · critical · RuntimeException

can't find myid properties file

Error message

can't find myid properties file : ${ZK_CONFIG_FILE_NAME}

What it means

ZkConfig.LoadMyidPropersites loads the ZooKeeper myid properties file named by ZK_CONFIG_FILE_NAME (typically zkcnf/myid.properties). When the file exists on the classpath but reading its stream throws an IOException, the catch block logs and rethrows as a RuntimeException. This means the file was found but could not be read/parsed.

Solutions

  1. Check the logged 'ZkConfig LoadMyidPropersites error' IOException cause for the real reason (permission, truncation, etc.).
  2. Verify zkcnf/myid.properties (or ZK_CONFIG_FILE_NAME) exists on the classpath and is readable by the Mycat process user (chmod/chown).
  3. Recreate the file with the required keys (zkURL, clusterId, myid) and valid properties syntax.
  4. Confirm the resource is packaged inside the jar/deployment if running from a fat jar.

Example fix

// before: unreadable/missing content in myid.properties

// after: recreate readable file with required keys
zkURL=127.0.0.1:2181
clusterId=cluster-1
myid=1
Defensive patterns

Strategy: validation

Validate before calling

java.io.InputStream is = getClass().getResourceAsStream(zkConfigFileName);
if (is == null) throw new IllegalStateException("missing " + zkConfigFileName);
Properties p = new Properties();
try (is) { p.load(is); } catch (IOException e) { throw new IllegalStateException("unreadable " + zkConfigFileName, e); }

Try / catch

try { ZkConfig.initZk(); } catch (RuntimeException e) { if (e.getMessage().contains("can't find myid properties file")) { log.error("Check {} readability/permissions on classpath", ZK_CONFIG_FILE_NAME, e); } throw e; }

Prevention

When it happens

Trigger: pros.load(configIS) throws IOException while reading the stream opened for ZK_CONFIG_FILE_NAME; the RuntimeException is thrown at ZkConfig.java:114 during startup when ZkConfig.main / static init calls LoadMyidPropersites.

Common situations: myid.properties exists but is unreadable due to file permissions, a truncated or empty file, a jar-packaged resource that failed to open, wrong encoding, or the file being locked/replaced while the classloader stream is opened.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/987ab25fac7f23cf. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java:114

    /**
     * 加载myid配制文件信息
    * 方法描述
    * @return
    * @创建日期 2016年9月15日
    */
    private static Properties LoadMyidPropersites() {
        Properties pros = new Properties();

        try (InputStream configIS = ZkConfig.class.getResourceAsStream(ZK_CONFIG_FILE_NAME)) {
            if (configIS == null) {
                return null;
            }

            pros.load(configIS);
        } catch (IOException e) {
            LOGGER.error("ZkConfig LoadMyidPropersites error:", e);
            throw new RuntimeException("can't find myid properties file : " + ZK_CONFIG_FILE_NAME);
        }

        // validate
        String zkURL = pros.getProperty(ZkParamCfg.ZK_CFG_URL.getKey());
        String myid = pros.getProperty(ZkParamCfg.ZK_CFG_MYID.getKey());

        String clusterId = pros.getProperty(ZkParamCfg.ZK_CFG_CLUSTERID.getKey());

        if (Strings.isNullOrEmpty(clusterId) ||Strings.isNullOrEmpty(zkURL) || Strings.isNullOrEmpty(myid)) {
            throw new RuntimeException("clusterId and zkURL and myid must not be null or empty!");
        }
        return pros;

    }

    public static void main(String[] args) {
        String zk = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_CLUSTERID);
        System.out.println(zk);

View on GitHub (pinned to 65f8d8beb7)