Code review comment: The original code will set the MetaContext of the current thread to `null`, any subsequent invoking of the following methods will throw NullPointerException:  https://github.com/StarRocks/starrocks/blob/d350c6cf0979eefe05dec25faa72bd141bbafb9a/fe/fe-core/src/main/java/com/starrocks/catalog/Catalog.java#L704  https://github.com/StarRocks/starrocks/blob/d350c6cf0979eefe05dec25faa72bd141bbafb9a/fe/fe-core/src/main/java/com/starrocks/catalog/Catalog.java#L700  A specific case of failure caused by this issue that I know is the following unit test: https://github.com/StarRocks/starrocks/blob/d350c6cf0979eefe05dec25faa72bd141bbafb9a/fe/fe-core/src/test/java/com/starrocks/catalog/TempPartitionTest.java#L203

Code under review:
public static boolean copy(Writable orig, Writable dest, Class c) {
        
        MetaContext oldContext = MetaContext.get();
        MetaContext metaContext = new MetaContext();
        metaContext.setMetaVersion(FeConstants.meta_version);
        metaContext.setStarRocksMetaVersion(FeConstants.starrocks_meta_version);
        metaContext.setThreadLocalInfo();

        FastByteArrayOutputStream byteArrayOutputStream = new FastByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(byteArrayOutputStream);
        try {
            orig.write(out);
            out.flush();
            out.close();

            DataInputStream in = new DataInputStream(byteArrayOutputStream.getInputStream());

            Method readMethod = c.getDeclaredMethod(READ_METHOD_NAME, DataInput.class);
            readMethod.invoke(dest, in);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            LOG.warn("failed to copy object.", e);
            return false;
        } finally {
            
            if (oldContext != null) {
                oldContext.setThreadLocalInfo();
            } else {
                MetaContext.remove();
            }
        }
        return true;
    }

Line commented on: MetaContext oldContext = MetaContext.get();

Revised code:
public static boolean copy(Writable orig, Writable dest, Class c) {
        
        MetaContext oldContext = MetaContext.get();
        MetaContext metaContext = new MetaContext();
        metaContext.setMetaVersion(FeConstants.meta_version);
        metaContext.setStarRocksMetaVersion(FeConstants.starrocks_meta_version);
        metaContext.setThreadLocalInfo();

        FastByteArrayOutputStream byteArrayOutputStream = new FastByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(byteArrayOutputStream);
        try {
            orig.write(out);
            out.flush();
            out.close();

            DataInputStream in = new DataInputStream(byteArrayOutputStream.getInputStream());

            Method readMethod = c.getDeclaredMethod(READ_METHOD_NAME, DataInput.class);
            readMethod.invoke(dest, in);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            LOG.warn("failed to copy object.", e);
            return false;
        } finally {
            
            if (oldContext != null) {
                oldContext.setThreadLocalInfo();
            } else {
                MetaContext.remove();
            }
        }
        return true;
    }