As @Evian said, the primary and secondary in the replica set are not fixed, but come from the election, so the previous failover of the machine can be realized. However, like the questioner, if you hope that a certain machine is more likely to become the primary, then set its priority to be higher than your machine in Alibaba Cloud. The Priority document explains how to operate. Note that there must be at least 3 machines (including arbitor) for replica set to be meaningful.
In this way, your on-site machine has a high priority. As long as it is alive and the data is not too old, it will become the primary. In the beginning, no one has data, and the on-site machine will naturally become the primary because of its high priority. . If the on-site machine hangs up, the other two machines in Alibaba Cloud will automatically select a new primary as the majority and continue to work happily. Of course, there will be no problem reading data. At this time, if the on-site machine comes back to life, or the network is restored, and Alibaba Cloud's machine finds that the on-site machine is more suitable to be the primary, it will actively step down, and the on-site machine will automatically become the primary, as if nothing has happened... …See Priority’s documentation.
This idea is very reasonable.
As @Evian said, the primary and secondary in the replica set are not fixed, but come from the election, so the previous failover of the machine can be realized. However, like the questioner, if you hope that a certain machine is more likely to become the primary, then set its priority to be higher than your machine in Alibaba Cloud. The Priority document explains how to operate. Note that there must be at least 3 machines (including arbitor) for replica set to be meaningful.
In this way, your on-site machine has a high priority. As long as it is alive and the data is not too old, it will become the primary. In the beginning, no one has data, and the on-site machine will naturally become the primary because of its high priority. . If the on-site machine hangs up, the other two machines in Alibaba Cloud will automatically select a new primary as the majority and continue to work happily. Of course, there will be no problem reading data. At this time, if the on-site machine comes back to life, or the network is restored, and Alibaba Cloud's machine finds that the on-site machine is more suitable to be the primary, it will actively step down, and the on-site machine will automatically become the primary, as if nothing has happened... …See Priority’s documentation.